Ignore:
Timestamp:
Mar 10, 2024, 11:21:18 AM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
9398177
Parents:
b64d0f4
Message:

more switch to tabs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/programs/bkgd-carray-mdim.c

    rb64d0f4 r5546f50b  
    1414
    1515int main() {
     16        float a[3][10];
     17        static_assert(sizeof(float)==4);                        $\C{// floats (atomic elements) are 4 bytes}$
     18        static_assert(sizeof(void*)==8);                        $\C{// pointers are 8 bytes}$
    1619
    17 /*
    18 As in the last section, we inspect the declaration ...
    19 */
    20     float a[3][10];
    21 /*
     20        static_assert(sizeof( a ) == 120);                      $\C{// the array, float[3][10]}$
     21        static_assert(sizeof( a[0] ) == 40);            $\C{// its first element, float[10]}$
     22        static_assert(sizeof( a[0][0] ) == 4 );         $\C{// its first grand element, float}$
    2223
    23 */
    24     static_assert(sizeof(float)==4);    // floats (atomic elements) are 4 bytes
    25     static_assert(sizeof(void*)==8);    // pointers are 8 bytes
    26 /*
     24        static_assert(sizeof(&(a)) == 8);                       $\C{// pointer to the array, float(*)[3][10]}$
     25        static_assert(sizeof(&(a[0])) == 8  );          $\C{// pointer to its first element, float(*)[10]}$
     26        static_assert(sizeof(&(a[0][0])) == 8  );       $\C{// pointer to its first grand-element, float*}$
    2727
    28 The significant axis of deriving expressions from @a@ is now ``itself,'' ``first element'' or ``first grand-element (meaning, first element of first element).''
    29 */
    30     static_assert(sizeof(  a       ) == 120); // the array, float[3][10]
    31     static_assert(sizeof(  a[0]    ) == 40 ); // its first element, float[10]
    32     static_assert(sizeof(  a[0][0] ) == 4  ); // its first grand element, float
     28        float (*pa  )[3][10] = &(a        );
     29        float (*pa0 )   [10] = &(a[0]   );
     30        float  *pa00             = &(a[0][0]);
    3331
    34     static_assert(sizeof(&(a      )) == 8  ); // pointer to the array, float(*)[3][10]
    35     static_assert(sizeof(&(a[0]   )) == 8  ); // pointer to its first element, float(*)[10]
    36     static_assert(sizeof(&(a[0][0])) == 8  ); // pointer to its first grand-element, float*
     32        static_assert((void*)&a == (void*)&(a[0]   ));
     33        static_assert((void*)&a == (void*)&(a[0][0]));
    3734
    38     float (*pa  )[3][10] = &(a      );
    39     float (*pa0 )   [10] = &(a[0]   );
    40     float  *pa00         = &(a[0][0]);
     35        assert( (void *) pa == (void *) pa0  );
     36        assert( (void *) pa == (void *) pa00 );
    4137
    42     static_assert((void*)&a == (void*)&(a[0]   ));
    43     static_assert((void*)&a == (void*)&(a[0][0]));
    44 
    45     assert( (void *) pa == (void *) pa0  );
    46     assert( (void *) pa == (void *) pa00 );
    47 
    48 //    float (*b[3])[10];
    49     float *b[3];
    50     for (int i = 0; i < 3; i ++) {
    51         b[i] = malloc(sizeof(float[10]));
    52     }
    53     a[2][3];
    54     b[2][3];
     38//      float (*b[3])[10];
     39        float *b[3];
     40        for (int i = 0; i < 3; i ++) {
     41                b[i] = malloc(sizeof(float[10]));
     42        }
     43        a[2][3];
     44        b[2][3];
    5545/*
    5646
Note: See TracChangeset for help on using the changeset viewer.