Before the C language variables in memory arrangement of some confusion, so a brief consolidation following aspects (All examples are based on X86 PC Ubuntu on the GCC compiler).
- When the variable definitions, the growth direction of the memory address assigned to different variables
(1) defines two global variables, after which the assignment compiled print the address allocated in memory, the variables found in the first definition is assigned the lowest address memory
(2) X86 PC Ubuntu's main function defined variables, using the memory address when compiling gcc view the system variables assigned (growth direction of the memory allocation is lower to higher addresses) - After the structure is instantiated, the growth direction of the member structure of the allocated memory address
(1) to define the global structure and initialized, the growth direction of the view structure after gcc compiler members memory allocation growth direction (the memory allocated by the low to high growth upward)
(2) of the structure in the main function and initialization, the growth direction of the view structure member gcc compiler memory allocation growth direction (the memory is allocated from low to high upwards growth) - Memory growth direction of stack space functions in the definition of variables used
- arm during use the arm cross compiler tool chain, the memory allocation is generally variable upward growth direction, but for full reduction stack manner used when the memory allocated on the stack growth on the stack memory allocated to the variables used, the stack downward direction when the direction of growth.