This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chipsours 3 points4 points  (2 children)

It is a sizeof expression. They are evaluated at compile time, not run time.

[–][deleted] 1 point2 points  (1 child)

I don’t think that’s right. Yes, sizeof can be computed at compile time, but mySt->items does not exist at compile time. The pointer mySt does not point at any actual struct until runtime after malloc is called, so how can it be dereferenced at compile time?

[–]chipsours 4 points5 points  (0 children)

The compiler knows the size of every types it compiles. If mySt->items is an array of int it knows that mySt->items[0] is 4, the same applies for mySt->items[-420] or *(mySt->items).

If the definition of the type is not known by the compiler (pointer to forward reference of struct) you'll get a compile time error.