Changeset b5bfb16 for doc/theses/mike_brooks_MMath/programs
- Timestamp:
- Mar 27, 2024, 10:08:54 AM (18 months ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/bkgd-carray-arrty.c
rb8cb388 rb5bfb16 32 32 33 33 int 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}$ 41 41 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}$ 44 44 @x = y;@ $\C{// ill-typed}$ 45 45 @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}$ 50 50 51 51 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}$ 56 56 } 57 f( & a);57 f( &ar ); 58 58 59 59 float fs[] = {3.14, 1.707}; 60 60 char cs[] = "hello"; 61 62 61 static_assert( sizeof(fs) == 2 * sizeof(float) ); 63 62 static_assert( sizeof(cs) == 6 * sizeof(char) ); $\C{// 5 letters + 1 null terminator}$ 63 64 64 } 65 65 … … 144 144 void stx2() { const T x[10]; 145 145 // x[5] = 3.14; // bad 146 146 } 147 147 void stx3() { T const x[10]; 148 148 // x[5] = 3.14; // bad 149 149 } 150 150 151 151 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.