bug raport - about way of linking in c

K

Keith Thompson

Jens Gustedt said:
Am 03.10.2012 23:07, schrieb Keith Thompson:

No it isn't. The standard has it even as example in two places. As
long as it is part of a definition and as long as you are not calling
main recursively, this is ok.

I can't find an example of "void main" in the C standard (I've checked
several versions). Perhaps my PDF reader's search function isn't good
enough. Can you be more specific?

I acknowledged that the statement isn't *quite* accurate; I stand by my
statement that it's close enough. I didn't want to go into the details
that we've discussed here at length in the past.

Take a look at section 5.1.2.2.1, and note in particular the use of the
word "shall".

A hosted implementation must accept "int main(void)" and "int main(int
argc, char *argv[])" or equivalent. It *may* (but need not) accept
other implementation-defined forms. The term "implementation-defined"
requires such forms to be documented.

If I write "void main(void) { /* ... */ }" and my implementation doesn't
explicitly state in its documentation that it accepts that form, then my
program's behavior is undefined. The implementation can accept it, or
it can can warn about it or reject it outright, or the program can
behave in any arbitrary manner at run time. If it does accept it, then
the behavior is implementation-defined -- except that if execution
reaches the closing "}", the termination status is unspecified. (I
hadn't noticed that last bit before; I'm a little surprised that it's
not implementation-defined rather than unspecified.)
Generally this "void main()" business is not a good example for things
that people should primarily learn about C. There are much more
important things to come first.

I agree that it's not all that important by itself, but I think it does
betray a certain lax attitude. For example, some of Schildt's books (at
least his older ones) use "void main()". If that were the only error,
it wouldn't be a huge deal, but it's a symptom of general sloppiness.
 
J

Jens Gustedt

Am 04.10.2012 21:47, schrieb Keith Thompson:
Keith, all my apologies, I was so fixed on this empty parameter list
issue that I didn't even saw the "void". And copied it!

So yes, you are right, having the wrong return type for main (and any
other function) is a real issue. In particular when it is known that
the return value will be used, which it will for certain in that case.

Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,078
Messages
2,570,570
Members
47,204
Latest member
MalorieSte

Latest Threads

Top