Ignore:
Timestamp:
May 24, 2024, 2:18:56 PM (6 weeks 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-decay.c

    rc721105 rdf699e0  
    11#include <assert.h>
    22int main() {
    3         float a[10];                            $\C{// array}$
    4         float (*pa)[10] = &a;           $\C{// pointer to array}$
    5         float a0 = a[0];                        $\C{// element}$
    6         float * pa0 = &(a[0]);          $\C{// pointer to element}$
     3        float ar[10];                           $\C{// array}$
     4        float (*pa)[10] = &ar;          $\C{// pointer to array}$
     5        float a0 = ar[0];                       $\C{// element}$
     6        float * pa0 = &(ar[0]);         $\C{// pointer to element}$
    77
    8         float * pa0x = a;                       $\C{// (ok)}$
     8        float * pa0x = ar;                      $\C{// (ok)}$
    99        assert( pa0 == pa0x );
    10         assert( sizeof(pa0x) != sizeof(a) );
     10        assert( sizeof(pa0x) != sizeof(ar) );
    1111
    1212        void f( float x[10], float * y ) {
     
    1414                static_assert( sizeof(y) == sizeof(void *) );
    1515        }
    16         f(0,0);
     16        f( 0, 0 );
    1717
    1818        // reusing local var `float a[10];`}
    1919        float v;
    20         f( a, a );                                      $\C{// ok: two decays, one into an array spelling}$
     20        f( ar, ar );                            $\C{// ok: two decays, one into an array spelling}$
    2121        f( &v, &v );                            $\C{// ok: no decays; a non-array passes to an array spelling}$
    2222
     
    3333                static_assert( sizeof(x) == sizeof(void *) );
    3434        }
    35         static_assert( sizeof(a) == 10 * sizeof(float) );
    36         decay(a);
     35        static_assert( sizeof(ar) == 10 * sizeof(float) );
     36        decay( ar );
    3737
    3838        void no_decay( float (*px)[10] ) {
     
    4040        }
    4141        static_assert( sizeof(*pa) == 10 * sizeof(float) );
    42         no_decay(pa);
     42        no_decay( pa );
    4343}
    4444
    4545// Local Variables: //
    46 // compile-command: "sed -f sedcmd bkgd-carray-decay.c | gcc -x c -" //
     46// compile-command: "sed -f sedcmd bkgd-carray-decay.c | gcc-11 -Wall -Wextra -x c -" //
    4747// End: //
Note: See TracChangeset for help on using the changeset viewer.