iu2 wrote:
Hi all,
This code compiles:
int func1()
{
return 3;
}
void func2()
{
int a = func1();
}
In func2 the initialization of 'a' is done by calling to func1().
Is this ok accroding to ANSI C? (I thougt this is legal only in C+
+...)
Initialising automatic variables can be done with arbitrary
expressions, including function calls.
Initialising /static/ variables -- those explicitly declarared
static, and variables declared outside functions -- requires a
compile-time constant [1]. Maybe that's what you're thinking of?
I need to know it because the project I work on will have to be ported
to a different compiler (other than gcc), and I need to use ANSI C.
Then `-ansi -pedantic` and a whole bunch of other stuff -- I appear
to use
-Wall -Wno-unused -Wwrite-strings -W -Wmissing-prototypes -fno-builtin
is your friend.
[1] And for pointer values, something which is essentially "address of
static possibly plus a constant".
--
"Only he had not reckoned with the ways of Estcarp." /Witch World/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England