#include #include #include #define SHOW(x, fmt) printf( #x ": " fmt "\n", x ) #ifdef ERRS #define ERR(...) __VA_ARGS__ #else #define ERR(...) #endif int main() { float mx[3][10]; static_assert( sizeof(float) == 4 ); $\C[3.25in]{// floats (atomic elements) are 4 bytes}$ static_assert( sizeof(void *) == 8 ); $\C{// pointers are 8 bytes}$ static_assert( sizeof(mx) == 120 ); $\C{// the array, float[3][10]}$ static_assert( sizeof(mx[0]) == 40 ); $\C{// its first element, float[10]}$ static_assert( sizeof(mx[0][0]) == 4 ); $\C{// its first grand element, float}$ static_assert( sizeof(&(mx)) == 8 ); $\C{// pointer to the array, float(*)[3][10]}$ static_assert( sizeof(&(mx[0])) == 8 ); $\C{// pointer to its first element, float(*)[10]}$ static_assert( sizeof(&(mx[0][0])) == 8 ); $\C{// pointer to its first grand-element, float*}\CRT$ float (*pm)[3][10] = &(mx); float (*pm0)[10] = &(mx[0]); float *pm00 = &(mx[0][0]); static_assert( (void *)&mx == (void *)&(mx[0] ) ); static_assert( (void *)&mx == (void *)&(mx[0][0]) ); assert( (void *) pm == (void *) pm0 ); assert( (void *) pm == (void *) pm00 ); // float (*b[3])[10]; float * b[3]; for (int i = 0; i < 3; i ++) { b[i] = malloc(sizeof(float[10])); } mx[2][3]; b[2][3]; /* */ } // Local Variables: // // compile-command: "sed -f sedcmd bkgd-carray-mdim.c | gcc-11 -Wall -Wextra -x c -" // // End: //