Which of the following function declaration is illegal? WHY ???

Jun 11, 2020 at 5:11pm
Which of the following function declaration is illegal? WHY ???
a)

double func();
int main(){}
double func(){}
b)

double func(){};
int main(){}
c)

int main()
{
double func();
}
double func(){//statements}
d) None of the mentioned
Jun 11, 2020 at 5:16pm
What are your thoughts about the question?

Jun 11, 2020 at 5:27pm
"Yes".
Jun 11, 2020 at 6:29pm
the compiler will tell you, if you really do not know. Set up a little test program, and see which one breaks it.
Jun 11, 2020 at 6:34pm
c) has an unmatched {

:)
Last edited on Jun 11, 2020 at 6:34pm
Jun 11, 2020 at 6:44pm
@Ganado, darn those comments!

a & b are also illegal, the custom function violates the return contract. :)
Jun 11, 2020 at 6:51pm
If an ill-formed function exists, but no one is around to call it, is it still undefined behavior?

Edit: Apparently the answer my half-facetious question is 'no', it's only undefined behavior if control flow reaches the illegal point.
n4659 9.6.3
Flowing off the end of a constructor, a destructor, or a function with a cv void return type is
equivalent to a return with no operand. Otherwise, flowing off the end of a function other than main (6.6.1)
results in undefined behavior.
Last edited on Jun 11, 2020 at 7:02pm
Jun 11, 2020 at 9:22pm
An ill-formed function simply causes the program to be rejected by the compiler. ;-)
Jun 11, 2020 at 9:34pm
I should be more careful with my standardese :)
Last edited on Jun 11, 2020 at 9:34pm
Topic archived. No new replies allowed.