source: doc/theses/mike_brooks_MMath/programs/bkgd-carray-mdim.c@ 3f9a8d0

Last change on this file since 3f9a8d0 was 7972603, checked in by Michael Brooks <mlbrooks@…>, 22 months ago

Missing files from last thesis push

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include <stdio.h>
2#include <assert.h>
3#include <stdlib.h>
4
5#define SHOW(x, fmt) printf( #x ": " fmt "\n", x )
6
7#ifdef ERRS
8#define ERR(...) __VA_ARGS__
9#else
10#define ERR(...)
11#endif
12
13
14
15int main() {
16
17/*
18As in the last section, we inspect the declaration ...
19*/
20 float a[3][10];
21/*
22
23*/
24 static_assert(sizeof(float)==4); // floats (atomic elements) are 4 bytes
25 static_assert(sizeof(void*)==8); // pointers are 8 bytes
26/*
27
28The significant axis of deriving expressions from @a@ is now ``itself,'' ``first element'' or ``first grand-element (meaning, first element of first element).''
29*/
30 static_assert(sizeof( a ) == 120); // the array, float[3][10]
31 static_assert(sizeof( a[0] ) == 40 ); // its first element, float[10]
32 static_assert(sizeof( a[0][0] ) == 4 ); // its first grand element, float
33
34 static_assert(sizeof(&(a )) == 8 ); // pointer to the array, float(*)[3][10]
35 static_assert(sizeof(&(a[0] )) == 8 ); // pointer to its first element, float(*)[10]
36 static_assert(sizeof(&(a[0][0])) == 8 ); // pointer to its first grand-element, float*
37
38 float (*pa )[3][10] = &(a );
39 float (*pa0 ) [10] = &(a[0] );
40 float *pa00 = &(a[0][0]);
41
42 static_assert((void*)&a == (void*)&(a[0] ));
43 static_assert((void*)&a == (void*)&(a[0][0]));
44
45 assert( (void *) pa == (void *) pa0 );
46 assert( (void *) pa == (void *) pa00 );
47
48// float (*b[3])[10];
49 float *b[3];
50 for (int i = 0; i < 3; i ++) {
51 b[i] = malloc(sizeof(float[10]));
52 }
53 a[2][3];
54 b[2][3];
55/*
56
57*/
58
59}
Note: See TracBrowser for help on using the repository browser.