How does the c++ compiler organize the variables that are initialized in a function to store them so the computer will find them the fastest way?
I understand that the compiler puts them one after an other on the stack but there has to be some logic behind it, I was searching Google for hours on end but I could not find anything.
For example:
int main()
{
float a;
int b;
char c;
double d;
}
This should occupy more memory than the one below because of the way the c++ compiler is storing in the memory.
The exact bits used are the same, of course, but they should be stored in a more efficient order in the example below. Where in memory would these variables be stored by the compiler in the next example? As far as I understood a variable is always stored on a block such that (logical number) % (number of bytes the datatype) = 0
int main()
{
char c;
int b;
float a;
double d;
}