Last change
on this file since 4205c07 was b195498, checked in by Peter A. Buhr <pabuhr@…>, 5 months ago |
proofreading intro and background chapters, capitalize section titles, update backtick calls to regular calls
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Rev | Line | |
---|
[7972603] | 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 |
|
---|
| 15 | int main() {
|
---|
[b195498] | 16 | float mx[3][10];
|
---|
| 17 | static_assert( sizeof(float) == 4 ); $\C[3.25in]{// floats (atomic elements) are 4 bytes}$
|
---|
| 18 | static_assert( sizeof(void *) == 8 ); $\C{// pointers are 8 bytes}$
|
---|
[5546f50b] | 19 |
|
---|
[b195498] | 20 | static_assert( sizeof(mx) == 120 ); $\C{// the array, float[3][10]}$
|
---|
| 21 | static_assert( sizeof(mx[0]) == 40 ); $\C{// its first element, float[10]}$
|
---|
| 22 | static_assert( sizeof(mx[0][0]) == 4 ); $\C{// its first grand element, float}$
|
---|
[5546f50b] | 23 |
|
---|
[b195498] | 24 | static_assert( sizeof(&(mx)) == 8 ); $\C{// pointer to the array, float(*)[3][10]}$
|
---|
| 25 | static_assert( sizeof(&(mx[0])) == 8 ); $\C{// pointer to its first element, float(*)[10]}$
|
---|
| 26 | static_assert( sizeof(&(mx[0][0])) == 8 ); $\C{// pointer to its first grand-element, float*}\CRT$
|
---|
[5546f50b] | 27 |
|
---|
[b195498] | 28 | float (*pm)[3][10] = &(mx);
|
---|
| 29 | float (*pm0)[10] = &(mx[0]);
|
---|
| 30 | float *pm00 = &(mx[0][0]);
|
---|
[5546f50b] | 31 |
|
---|
[b195498] | 32 | static_assert( (void *)&mx == (void *)&(mx[0] ) );
|
---|
| 33 | static_assert( (void *)&mx == (void *)&(mx[0][0]) );
|
---|
[5546f50b] | 34 |
|
---|
[b195498] | 35 | assert( (void *) pm == (void *) pm0 );
|
---|
| 36 | assert( (void *) pm == (void *) pm00 );
|
---|
[5546f50b] | 37 |
|
---|
| 38 | // float (*b[3])[10];
|
---|
[b195498] | 39 | float * b[3];
|
---|
[5546f50b] | 40 | for (int i = 0; i < 3; i ++) {
|
---|
| 41 | b[i] = malloc(sizeof(float[10]));
|
---|
| 42 | }
|
---|
[b195498] | 43 | mx[2][3];
|
---|
[5546f50b] | 44 | b[2][3];
|
---|
[7972603] | 45 | /*
|
---|
| 46 |
|
---|
| 47 | */
|
---|
| 48 |
|
---|
| 49 | }
|
---|
[a885357] | 50 |
|
---|
| 51 | // Local Variables: //
|
---|
[df699e0] | 52 | // compile-command: "sed -f sedcmd bkgd-carray-mdim.c | gcc-11 -Wall -Wextra -x c -" //
|
---|
[a885357] | 53 | // End: //
|
---|
Note:
See
TracBrowser
for help on using the repository browser.