/* mha: you could read the FAQ before posting. Or if that's beyond
you, check the archives at groups.google.com. Those are the things
civilized people do before posting. In any case, consider the code
below */
#include <stdio.h>
#define array_size_info(a) do \
printf("The array has size %lu,"\
" each of the %lu elements has size %lu\n",\
sizeof a, sizeof a/sizeof *a, sizeof *a);\
while (0)
int main(void)
{
struct xy
{
int x;
int y;
}
xy[32];
array_size_info(xy);
return 0;
}
[output on my implementation]
The array has size 256, each of the 32 elements has size 8
#include <stdio.h>
#define array_size_info(a) do \
printf("The array has size %lu,"\
" each of the %lu elements has size %lu\n",\
sizeof a, sizeof a/sizeof *a, sizeof *a);\
while(0)
struct xy {
int x;
int y;
}
first_xy[32], second_xy[64];
void do_something(struct xy *_xy) {
array_size_info(_xy);
}
int main( void ) {
array_size_info( first_xy );
array_size_info( second_xy );
do_something(first_xy);
do_something(second_xy);
return 0;
}
the output is:
The array has size 256, each of the 32 elements has size 8
The array has size 512, each of the 64 elements has size 8
The array has size 4, each of the 0 elements has size 8
The array has size 4, each of the 0 elements has size 8
as you can see array_size_info works wrong in do_something();