C the same global variable defined in different files

前端 未结 6 960
我在风中等你
我在风中等你 2020-12-04 17:09

I am reading this code from here(in Chinese). There is one piece of code about testing global variable in C. The variable a has been defined in the file t

6条回答
  •  误落风尘
    2020-12-04 17:38

    At the time foo is being compiled, the b that is in scope is the two ints vector {2, 4} or 8 bytes when an sizeof(int) is 4. When main is compiled, b has just been redeclared as an int so a size of 4 makes sense. Also there is probably "padding bytes" added to the struct after "a" such that the next slot (the int) is aligned on 4 bytes boundary.

提交回复
热议问题