Are these two statements equivalent??
Code:struct coords { double x, y , z; }; typedef coords points[50];Code:typedef struct { double x, y , z; }coords; coords points[50];
Are these two statements equivalent??
Code:struct coords { double x, y , z; }; typedef coords points[50];Code:typedef struct { double x, y , z; }coords; coords points[50];
Yes they are.
> Are these two statements equivalent??
No.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well in C, you would need
typedef struct coords points[50];
The new typename in this is just points. It being a synonym for an array of 50 coords.
With this, you could just have:
points p;
and then go on to say:
p[0].x = 0;
Whilst legal code, typedef'ing arrays is like typedef'ing pointers(*) - it seems to obscure more than it enhances.
(*)
The exception is typedef'ing pointers to functions, which should be typedef'ed all the time IMO.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.