Last active
October 2, 2019 14:47
-
-
Save rpoisel/7a9518349ab0f52321a4f60a158e7231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdio.h> | |
typedef struct { | |
int a; | |
int b; | |
} MyLine; | |
typedef struct { | |
MyLine const *firstElement; | |
size_t dim_y; | |
size_t dim_x; | |
} MyTable; | |
typedef MyTable const *MyTableConstPtr; | |
#define MyTableConstr(d) \ | |
{ \ | |
.firstElement = &d[0][0], .dim_y = sizeof(d) / sizeof(d[0]), \ | |
.dim_x = sizeof(d[0]) / sizeof(d[0][0]) \ | |
} | |
static void printFun(MyTableConstPtr table) { | |
printf("Dim x = %lu, Dim y = %lu\n\n", table->dim_y, table->dim_x); | |
for (size_t cnt = 0; cnt < table->dim_x * table->dim_y; cnt++) { | |
printf("%d, %d\n", table->firstElement[cnt].a, | |
table->firstElement[cnt].b); | |
} | |
} | |
int main(void) { | |
static MyLine const myData1[][2] = { | |
{{0, 1}, {2, 3}}, {{4, 5}, {6, 7}}, {{8, 9}, {10, 11}}}; | |
MyTable const myTable1 = MyTableConstr(myData1); | |
static MyLine const myData2[][3] = {{{0, 1}, {2, 3}, {4, 5}}, | |
{{6, 7}, {8, 9}, {10, 11}}, | |
{{12, 13}, {14, 15}, {16, 17}}}; | |
MyTable const myTable2 = MyTableConstr(myData2); | |
printFun(&myTable1); | |
printf("--\n"); | |
printFun(&myTable2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment