Ignore:
Timestamp:
Mar 27, 2024, 10:08:54 AM (18 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
2d82999
Parents:
b8cb388
git-author:
Peter A. Buhr <pabuhr@…> (03/27/24 10:08:01)
git-committer:
Peter A. Buhr <pabuhr@…> (03/27/24 10:08:54)
Message:

start proofreading of Section 2.1

File:
1 edited

Legend:

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

    rb8cb388 rb5bfb16  
    3232
    3333int main() {
    34         float a[10];
    35         static_assert(sizeof(float) == 4);              $\C{// floats (array elements) are 4 bytes}$
    36         static_assert(sizeof(void*) == 8);              $\C{// pointers are 8 bytes}$
    37         static_assert(sizeof(a) == 40);                 $\C{// array}$
    38         static_assert(sizeof(&a) == 8 );                $\C{// pointer to array}$
    39         static_assert(sizeof(a[0]) == 4 );              $\C{// first element}$
    40         static_assert(sizeof(&(a[0])) == 8 );   $\C{// pointer to first element}$
     34        float ar[10];
     35        static_assert( sizeof(float) == 4 );    $\C{// floats (array elements) are 4 bytes}$
     36        static_assert( sizeof(void*) == 8 );    $\C{// pointers are 8 bytes}$
     37        static_assert( sizeof(ar) == 40 );              $\C{// array}$
     38        static_assert( sizeof(&ar) == 8 );              $\C{// pointer to array}$
     39        static_assert( sizeof(ar[0]) == 4 );    $\C{// first element}$
     40        static_assert( sizeof(&(ar[0])) == 8 ); $\C{// pointer to first element}$
    4141
    42         typeof(&a) x;                                                   $\C{// x is pointer to array}$
    43         typeof(&(a[0])) y;                                              $\C{// y is pointer to first element}$
     42        typeof(&ar) x = &ar;                                    $\C{// x is pointer to array}$
     43        typeof(&(ar[0])) y = &ar[0];                    $\C{// y is pointer to first element}$
    4444        @x = y;@                                                                $\C{// ill-typed}$
    4545        @y = x;@                                                                $\C{// ill-typed}$
    46         static_assert(sizeof(typeof(a)) == 40);
    47         static_assert(sizeof(typeof(&a)) == 8 );
    48         static_assert(sizeof(typeof(a[0])) == 4 );
    49         static_assert(sizeof(typeof(&(a[0]))) == 8 );
     46        static_assert( sizeof(typeof(ar)) == 40 ); $\C{// array}$
     47        static_assert( sizeof(typeof(&ar)) == 8 );      $\C{// pointer to array}$
     48        static_assert( sizeof(typeof(ar[0])) == 4 ); $\C{// first element}$
     49        static_assert( sizeof(typeof(&(ar[0]))) == 8 ); $\C{// pointer to first element}$
    5050
    5151        void f( float (*pa)[10] ) {
    52             static_assert(sizeof(   *pa     ) == 40); $\C{// array}$
    53             static_assert(sizeof(    pa     ) == 8 ); $\C{// pointer to array}$
    54             static_assert(sizeof( (*pa)[0] ) == 4 ); $\C{// first element}$
    55             static_assert(sizeof(&((*pa)[0])) == 8 ); $\C{// pointer to first element}$
     52                static_assert( sizeof( *pa ) == 40 ); $\C{// array}$
     53                static_assert( sizeof( pa ) == 8 );     $\C{// pointer to array}$
     54                static_assert( sizeof( (*pa)[0] ) == 4 ); $\C{// first element}$
     55                static_assert( sizeof(&((*pa)[0])) == 8 ); $\C{// pointer to first element}$
    5656        }
    57         f( & a );
     57        f( &ar );
    5858
    5959        float fs[] = {3.14, 1.707};
    6060        char cs[] = "hello";
    61 
    6261        static_assert( sizeof(fs) == 2 * sizeof(float) );
    6362        static_assert( sizeof(cs) == 6 * sizeof(char) );  $\C{// 5 letters + 1 null terminator}$
     63
    6464}
    6565
     
    144144void stx2() { const T x[10];
    145145//            x[5] = 3.14; // bad
    146                 }
     146                        }
    147147void stx3() { T const x[10];
    148148//            x[5] = 3.14; // bad
    149                 }
     149                        }
    150150
    151151// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.