Thanks Eric and Ben for the responses. So firstly it is a declaration not a statement and secondly the type of my is defined at the point sizeof is applied to *my.
Right.
For completeness, there are a few situations where `sizeof' could
not be evaluated. One is when `struct mystruct' is an "incomplete"
type, that is, when there has been no
struct mystruct {
double trouble;
short shrift;
char broiled;
...
};
declaration earlier giving the details of the `struct mystruct' type.
(Your example didn't show such a prior declaration, but it would need
to have been there for your example to work at all, so both Ben and I
"took it as read.") You can form pointers to objects of incomplete
type, but the size (and details) of the pointed-to object is unknown.
Another is when declaring an array of unspecified size, where
the initializers determine the array size. For example,
int array[] = { 1, 2, 3, 4 }; // four elements
char string[] = "Hello, world!"; // fourteen (13+1) elements
are perfectly all right. But in these cases, the initializers
govern the array sizes so `sizeof array' and `sizeof string' aren't
known until after the initialization. Something like
int wrong[] = { 1, 2, 3, sizeof wrong, 42 };
would not work.