Ignore:
Timestamp:
May 24, 2024, 2:18:56 PM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
a4808ad
Parents:
c721105
Message:

program updates to match text

File:
1 edited

Legend:

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

    rc721105 rdf699e0  
    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}$
     16        float ar[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}$
    1919
    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}$
     20        static_assert(sizeof(ar) == 120);                       $\C{// the array, float[3][10]}$
     21        static_assert(sizeof(ar[0]) == 40);                     $\C{// its first element, float[10]}$
     22        static_assert(sizeof(ar[0][0]) == 4);           $\C{// its first grand element, float}$
    2323
    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*}$
     24        static_assert(sizeof(&(ar)) == 8);                      $\C{// pointer to the array, float(*)[3][10]}$
     25        static_assert(sizeof(&(ar[0])) == 8);           $\C{// pointer to its first element, float(*)[10]}$
     26        static_assert(sizeof(&(ar[0][0])) == 8);        $\C{// pointer to its first grand-element, float*}$
    2727
    28         float (*pa  )[3][10] = &(a        );
    29         float (*pa0 )   [10] = &(a[0]   );
    30         float  *pa00             = &(a[0][0]);
     28        float (*pa)[3][10] = &(ar);
     29        float (*pa0)[10] = &(ar[0]);
     30        float *pa00 = &(ar[0][0]);
    3131
    32         static_assert((void*)&a == (void*)&(a[0]  ));
    33         static_assert((void*)&a == (void*)&(a[0][0]));
     32        static_assert((void*)&ar == (void*)&(ar[0] ));
     33        static_assert((void*)&ar == (void*)&(ar[0][0]));
    3434
    35         assert( (void *) pa == (void *) pa0  );
     35        assert( (void *) pa == (void *) pa0 );
    3636        assert( (void *) pa == (void *) pa00 );
    3737
     
    4141                b[i] = malloc(sizeof(float[10]));
    4242        }
    43         a[2][3];
     43        ar[2][3];
    4444        b[2][3];
    4545/*
     
    5050
    5151// Local Variables: //
    52 // compile-command: "sed -f sedcmd bkgd-carray-mdim.c | gcc -x c -" //
     52// compile-command: "sed -f sedcmd bkgd-carray-mdim.c | gcc-11 -Wall -Wextra -x c -" //
    5353// End: //
Note: See TracChangeset for help on using the changeset viewer.