I have a structure and wish to print all member variable like an array.
The struct was like
#pragma pack(push) /* push current alignment to stack */
#pragma pack(1) /* set alignment to 1 boundary */
struct testStruct {
int a = 6;
int b[5] = {1,2,3,4,5};
} testStruct1 ;
#pragma pack(pop) /* restore original alignment from stack */
I am trying stuff like
for(int i = 0; i < 6; i++)
{
printf("%d, ", testStruct1 + i);
}
This cannot compile. I'm not willing to declare a new array to memcpy all member in it.
I wish to see
6, 1, 2, 3, 4, 5,
Is there any way to do so??? Thanks
printf( "%d, ", teststruct1.b[i] );printX()or write a loop running over the array.printf()does not know how to print arrays.testStruct1 + iis incorrect since a) testStruct1 isn't even a pointer to a struct and b) Pointers to structs would also not work that way .