www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/26/22:28:51

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199606270225.AA264472333@relay1.geis.com>
Date: Thu, 27 Jun 96 02:02:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: Does DJGPP conform to ANSI

Reply to message 9316808    from LAV AT VIDEO DOT YAR on 06/26/96  2:56PM


>> so is this 'conforming' or not? While we're at it, what's 'conforming'?
>
>I'm not sure, try asking in comp.std.c

IMHO, the smallest _strictly_ conforming C program looks like this:

int main( void )
{
    return 0;
}

Yes, I know that an undefined return type defaults to int, but it's bad
programming in general to leave things like that up to the compiler.

>> I think if the above is not conforming, it should issue an error,
>> right?
>
>The original poster said that void main is not conforming, but gcc
>does not give a warning.

There's a difference between non-conforming and illegal.  The reason
that you don't get errors for basic things like that is that the compiler
assumes that you intended to do it that way in the first place.  It also
only gives warnings for things that might cause unpredictable behavior
in your program.  Not returning in a function with a return value can be
extremely dangerous, so the compiler warns you about it.  But it doesn't
force you to change it.

Another thing that I wanted to mention - as I understand it there is a
significant difference between "main()", and "main(void)".  They are
the same under ANSI C, but under traditional C the first indicates a
function that can be passed any kind of arguments whatsoever, while
the second is syntactically incorrect, because traditional C has no 'void'
type.  Thus, if you want to write strictly ANSI conforming programs, it
is in your best interests to put 'void' in there, because it prevents a
traditional compiler from making invalid assumptions about your program.

Just my 2 copper pieces worth.

John

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019