suppose I have a class defined as follows
class foo
{
char [10] bar;
}
How would the size of this class differ when in a 64 bit environment compared to a 32 bit one, assuming no padding/packing.
I believe the 64 bit version of the class would be 4 more bytes in length since:
- The class must contain a char* in order to point to the start of the array bar
- an char* is 8 bytes in a 64 bit environment vs 4 bytes in a 32 bit environment
Am I correct?
Thanks!
A further question about how arrays actually work
If there is no pointer stored when you declare an array, how come you can get an address out of the array name and do things like bar[0], bar[1], etc?
No you are not.
char [] bar;won’t even compile,char bar[10];is the correct syntax, and no, no pointer is stored, sizeof(char) is always 1 and sizeof bar will be 10, regardless of the architecture.Now for your additional question:
You must understand the notion of lvalues and rvalues and lvalue-to-rvalue conversions. Usually lvalue-to-rvalue conversions “do nothing”. An excetion is that an lvalue-to-rvalue conversion for array of T is conversion to a pointer to T which points to the first element of the array.
Also a function declaration taking an array of T by value is equivalent to a function declaration taking a pointer to T.