Programmer --- C language details 29 (# define grand and small, empty struct size, flexible array I don't know if you have seen it ),
Main Content: # define large and small, empty struct size, flexible array
I. # define grand and small
See examples
Ii. Empty struct size
Related to the root Compiler
3. Flexible Array
Not commonly used.
# Include <stdio. h> # define N 4 # define STR "abcd"/* macro definition test */# define ewaece # define sizeof // The macro definition compilation error below, the above two can be compiled through // # define intint main () {struct student {} stu; printf ("N = % d \ n", sizeof (N )); printf ("num 5 memery = % d \ n", sizeof (5); printf ("char 'D' = % d \ n ", sizeof ('D'); printf ("STR = % d \ n", sizeof (STR); printf ("a = % d \ n ", sizeof (stu); // output 0 in gcc and mingw5 compiler, and 1 in vc ++ 6.0 (My mingw5 compiler ), in vc ++ 6.0, the minimum size of the struct is 1 byte by default (contains an empty struct and only contains one char struct) /* for flexible array testing, refer to deep anatomy of C language */printf ("\ n flexible array testing \ n"); typedef struct test {int I; int a []; // This array must contain another member} te; printf ("sizeof (te) = % d \ n", sizeof (te )); // int a [] is not a member of the struct te * p = (te *) malloc (sizeof (te) + sizeof (int) * 100 ); p-> a [0] = 13; printf ("p-> a [0] = % d \ n", p-> a [0]); printf ("sizeof (p) = % d \ n", sizeof (p); // The size is still 4, because int a [] is not a member of the struct, return 0 ;}
Output: