Re: Function call before main.
- From: "James Kuyper Jr." <jameskuyper@xxxxxxxxxxx>
- Date: Mon, 22 Oct 2007 11:24:08 GMT
Richard Heathfield wrote:
Srinu said:
Hi all,
Thanks a lot for all the answers.
I tried the following...It gives the same value 9 in TCC but showing
error: initializer element is not constant in gcc.
#include<stdio.h>
int f();
int x = f();
This is not valid C code. The rules of C do not give you licence to call a function from any part of the code other than inside another function. If you try to do so anyway, the compiler is free to reject your code, or to translate it in some arbitrary manner which may or may not be predictable on a given implementation.
He indicated that he was using a C++ compiler. The rules of C++ do allow it, and the results can be predictable, except when they depend upon the order of initialization of static objects, which isn't a problem in this example. Some pairs of objects do have guaranteed ordering, others do not - you have to know the relevant rules if you decide to write that kind of code.
Why he was asking a C group about the result of using a C++ compiler is a harder question.
.
- Follow-Ups:
- Re: Function call before main.
- From: santosh
- Re: Function call before main.
- From: Richard Heathfield
- Re: Function call before main.
- References:
- Function call before main.
- From: Srinu
- Re: Function call before main.
- From: Jack Klein
- Re: Function call before main.
- From: Srinu
- Re: Function call before main.
- From: Richard Heathfield
- Function call before main.
- Prev by Date: Re: about gcc 4.2
- Next by Date: Linux: Unbuffered reading from stdin
- Previous by thread: Re: Function call before main.
- Next by thread: Re: Function call before main.
- Index(es):
Relevant Pages
|