asit said:
Static variables can't be initialized with functions, becoz these are
load time processes. Why this is so ??
Static objects can only be initialised with constant expressions. "All the
expressions in an initializer for an object that has static storage
duration or in an initializer list for an object that has aggregate or
union type shall be constant expressions", says my C89 draft. "All the
expressions in an initializer for an object that has static storage
duration shall be constant expressions or string literals", says my C99
final.
Since the result of a function call can be neither a string literal
(although it might be a pointer to the first character therein) nor a
constant expression, it can't be used to initialise a static object.
Furthermore, C99 goes on to say that "All objects with static storage
duration shall be initialized (set to their initial values) before program
startup" (and C89 has very similar wording).
Since functions can't be called until the program has started, they can't
return values until the program has started - by which time all static
objects have already been initialised, so it's a bit late by then, right?
What is a load time process ??
Heaven knows.