Hi all,
Recently i was reading a c book which contained a section called C
pitfalls.
it had a paragraph on the following lines:-
-------------------------------------------------------------------
using nonconstant expressions in an initializer list
-------------------------------------------------------------------
struct s {int i;};
int foo(void);
struct s bar(void)
{
struct S s = {foo()}; /*problem here*/
return s;
}
Explanation:-
unlike other automatic variable initializers,the expressions in an
initializer list for a struct,union,or array must be constant
expressions. constant expressions are not values of constant qualified
objects.they are expressions that trivially(without the use of global
or flow analysis) can be evaluated by the compiler at compile time
constant expressions in initializers can include the following
1) arithmetic constant expressions comprised of arithmetic constants of
various types and sizeof expressions ex:- (sizeof(struct S) +7)/8 * 8
2) Null pointer constants
3) addresses of static duration objects,such as file scope variables or
of function designators
Now my questions are as follows:-
1) To what extent this explanation is true ??
2) I compiled the above code cleanly on a mingw 2.95.2-1 compiler !!
3) what is this global or flow analysis ??