Changeset 520fa9e for doc/theses/mike_brooks_MMath/programs
- Timestamp:
- Oct 30, 2024, 11:05:29 PM (11 months ago)
- Branches:
- master
- Children:
- 292d6cf6
- Parents:
- a3bd827
- Location:
- doc/theses/mike_brooks_MMath/programs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/programs/bkgd-carray-arrty.c
ra3bd827 r520fa9e 51 51 void f( float (*pa)[10] ) { 52 52 static_assert( sizeof( *pa ) == 40 ); $\C{// array}$ 53 static_assert( sizeof( pa ) == 8 ); 53 static_assert( sizeof( pa ) == 8 ); $\C{// pointer to array}$ 54 54 static_assert( sizeof( (*pa)[0] ) == 4 ); $\C{// first element}$ 55 55 static_assert( sizeof(&((*pa)[0])) == 8 ); $\C{// pointer to first element}$ … … 58 58 59 59 float fs@[]@ = {3.14, 1.77}; 60 char cs@[]@ = "hello"; // shorthand for 'h', 'e', 'l', 'l', 'o', '\0'60 char cs@[]@ = "hello"; // shorthand for { 'h', 'e', 'l', 'l', 'o', '\0' } 61 61 static_assert( sizeof(fs) == 2 * sizeof(float) ); 62 62 static_assert( sizeof(cs) == 6 * sizeof(char) ); $\C{// 5 letters + 1 null terminator}$ -
doc/theses/mike_brooks_MMath/programs/bkgd-carray-decay.c
ra3bd827 r520fa9e 30 30 edit( "hello" ); $\C{// Segmentation fault [decay here]}$ 31 31 32 void decay( float x[10]) {33 static_assert( sizeof(x) == sizeof(void *));32 void decay( @float x[10]@ ) { 33 static_assert(@sizeof(x) == sizeof(void *)@ ); 34 34 } 35 35 static_assert( sizeof(ar) == 10 * sizeof(float) ); 36 36 decay( ar ); 37 37 38 void no_decay( float (*px)[10]) {39 static_assert( sizeof(*px) == 10 * sizeof(float));38 void no_decay( @float (*px)[10]@ ) { 39 static_assert(@sizeof(*px) == 10 * sizeof(float)@); 40 40 } 41 41 static_assert( sizeof(*pa) == 10 * sizeof(float) ); -
doc/theses/mike_brooks_MMath/programs/bkgd-carray-mdim.c
ra3bd827 r520fa9e 15 15 int main() { 16 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}$17 static_assert( sizeof(float) == 4 ); $\C{// floats (atomic elements) are 4 bytes}$ 18 static_assert( sizeof(void*) == 8 ); $\C{// pointers are 8 bytes}$ 19 19 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}$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}$ 23 23 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*}$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*}$ 27 27 28 28 float (*pa)[3][10] = &(ar); … … 30 30 float *pa00 = &(ar[0][0]); 31 31 32 static_assert( (void*)&ar == (void*)&(ar[0] ));33 static_assert( (void*)&ar == (void*)&(ar[0][0]));32 static_assert( (void*)&ar == (void*)&(ar[0] ) ); 33 static_assert( (void*)&ar == (void*)&(ar[0][0]) ); 34 34 35 35 assert( (void *) pa == (void *) pa0 );
Note:
See TracChangeset
for help on using the changeset viewer.