Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > bug raport - about way of linking in c

Reply
Thread Tools

bug raport - about way of linking in c

 
 
Keith Thompson
Guest
Posts: n/a
 
      10-04-2012
Jens Gustedt <(E-Mail Removed)> writes:
> Am 03.10.2012 23:07, schrieb Keith Thompson:
>>> void main()

>>
>> And in your own language, you can use "void main()" as much as you like.
>> In C, it's wrong. (That's not *quite* accurate, but it's close enough.)

>
> 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.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Jens Gustedt
Guest
Posts: n/a
 
      10-05-2012
Am 04.10.2012 21:47, schrieb Keith Thompson:
> Jens Gustedt <(E-Mail Removed)> writes:
>> Am 03.10.2012 23:07, schrieb Keith Thompson:
>>>> void main()


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
Generating raport Luke Ruby 1 09-14-2006 06:51 AM
Getting linking error: not found in vtable (Trying to understand whats wrong the way I did my classes?) g35rider@gmail.com C++ 1 08-17-2006 05:10 PM
way way way OT: MCNGP Announcement Neil MCSE 174 04-17-2006 05:55 PM
AMD Opteron: 1-way, 2-way, ... Up to 8-way. John John Windows 64bit 12 12-27-2005 08:17 AM



Advertisments