Peter said:
The standards don't have anything to say on the resultant
executable size of a program for either case.
That said, either your globals _need_ initialising or they don't,
so I don't see the point of the question.
int global = 42;
...is a lot simpler and more robust than...
int global;
int main(void)
{
global = 42;
/* ... */
return 0;
}
In terms of source code, yes. In practice, no, for two reasons.
First, main may be called recursively in C, so the meanings are
quite different. Second, the presence of _any_ initialization for
'global' data may trigger large arrays of zeroes in the executable
on some systems. There is no standard for this, of course, but
the absence of such initialization ensures it doesn't happen.
This is a religious issue, and sure to draw fire, but I prefer to
NOT initialize and write specific initialization code where it is
needed. That way you are also not hiding the fact that local
(automatic) variable initialization generates code. It also
allows you to count on the fact of 0 initialization for static
variables.