C language variables in memory arrangement

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).

  1. 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
    C language variables in memory arrangement
    C language variables in memory arrangement
    (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)
    C language variables in memory arrangement
  2. 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)
    C language variables in memory arrangement
    (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)
    C language variables in memory arrangement
  3. Memory growth direction of stack space functions in the definition of variables used
    C language variables in memory arrangement
  4. 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.

Guess you like

Origin blog.51cto.com/4265810/2462587