Tool/software: TI C/C++ Compiler
I have a class that looks like this:
template<typename T> class ParameterCheck { public: ParameterCheck(volatile T* parameter_ptr, T init_value): last_value_(init_value), parameter_ptr_(parameter_ptr) {}; bool DidChange(void) { if (last_value_ != *parameter_ptr_) { last_value_ = *parameter_ptr_; return true; } return false; } private: T last_value_; volatile T* parameter_ptr_; };
In a function, I create arrays of this class like so:
static ParameterCheck<int32_t> i32_parameters[] = { ParameterCheck<int32_t>(¶meter1, 0), ParameterCheck<int32_t>(¶meter2, 0), ParameterCheck<int32_t>(¶meter3, 0), ParameterCheck<int32_t>(¶meter4, 0), ParameterCheck<int32_t>(¶meter5, 0), ParameterCheck<int32_t>(¶meter6, 0), }; static ParameterCheck<uint64_t> u64_parameters[] = { ParameterCheck<uint64_t>(¶meter7, 0ULL), ParameterCheck<uint64_t>(¶meter8, 0ULL) };
When I compile this and check the MAP file for the sizes of these structures, i32_parameters resolves to 48, which means each element is 8 bytes. That's what I would expect from a class with an in32_t and a pointer on a 32-bit processor. However when I check the size of u64_parameters, it reports 32 meaning that each element is 16 bytes. It should be 4 + 8 = 12 bytes. I get the same result if I make u64_parameters 3 elements instead of two. Why does the compiler add an additional 4 bytes here? Is there some alignment that I'm not accounting for? I know the compiler is supposed to satisfy a memory width of 4, but 12 is a multiple of 4. Does anyone have any insight as to why this might be happening?