Article View: alt.msdos.programmer
Article #1181Re: Pascal program works but not C program!
From: Lawrence Kirby
Date: Sat, 13 Jan 1996 15:11
Date: Sat, 13 Jan 1996 15:11
61 lines
3446 bytes
3446 bytes
In article <4d4742$n50@solutions.solon.com>
seebs@solutions.solon.com "Peter Seebach" writes:
>In article <4d3scf$4uk@gap.cco.caltech.edu>,
>Gary E. Ansok <ansok@alumnae.caltech.edu> wrote:
>>Implementations are free to accept other declarations of main(). Indeed,
>>the Rationale (not strictly part of the Standard, of course) says (p. 11)
>>"While many implementations support more than two arguments to main, such
>>practice is neither blessed nor forbidden by the Standard; a program that
>>defines main with three arguments is not _strictly conforming_."
>
>>So your program is not erroneous if it expects three arguments to main(),
>>as long as your compiler accepts it. It just isn't necessarily portable
>>to any other system (or compiler).
>
>Which is to say, it is no longer strictly conforming, which is to say, it's
>not really C anymore. A merely "conforming" program (one acceptable to
>at least *one* conforming C compiler) could be in FORTRAN; as long as the
>compiler gives at least one warning, it can translate anything it wants.
The difference there is that void main() doesn't require a diagnostic
from the compiler. This doesn't really put it on a higher level though.
>The key is that the use of a non-standard declaration of main, just like
>the use of strdup(), introduces "undefined behavior".
>
>On at least one implementation I know of, you can use "gets(NULL)" as
>a way to check a line of input without using a variable. This is
>also conforming code, and is *EXACTLY* as legal as "void main(void)" or
>"int main(argc, argv, envp) char **argv, **envp;".
or
i = i++;
or
double d;
scanf("%f", &d);
>>Yes, I think programmers should remove unnecessary non-portabilities
>>from their code. No, I don't think "void main()" should be the instant
>>flame-trigger it seems to be.
>
>I think it makes sense in a *C* newsgroup. If you write conforming code,
>you are SOL, and you may be making it gratuitously hard for people to help
>you with your problems. In general, problems with code that is not legit
>ANSI are hardly ever problems having to do with the C language; they are
>often problems with a given compiler or implementation, which means, they
>should be addressed in a newsgroup more related to that implementation.
Right. Starting a program with void main() is saying "I give free license
to the compiler to do whatever it likes with the code". Posting code in
comp.lang.c with (gratuitously) no defined meaning according to the C
language definitionjust adds noise to a newsgroup which already has plenty.
--
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID:
<821545862snz@genesis.demon.co.uk>Path:
arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.ukReferences:
<4cdpr2$psi@lugb.latrobe.edu.au> <4cp3vc$8nh@brahms.tfi.be> <4cpqt6$9r8@solutions.solon.com> <4d3scf$4uk@gap.cco.caltech.edu> <4d4742$n50@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk From: Lawrence Kirby <fred@genesis.demon.co.uk> Newsgroups: alt.msdos.programmer,comp.lang.c Subject: Re: Pascal program works but not C program! Date: Sat, 13 Jan 96 15:11:02 GMT Organization: none Message-ID: <821545862snz@genesis.demon.co.uk> References: <4cdpr2$psi@lugb.latrobe.edu.au> <4cp3vc$8nh@brahms.tfi.be> <4cpqt6$9r8@solutions.solon.com> <4d3scf$4uk@gap.cco.caltech.edu> <4d4742$n50@solutions.solon.com> Reply-To: fred@genesis.demon.co.uk X-NNTP-Posting-Host: genesis.demon.co.uk X-Newsreader: Demon Internet Simple News v1.27 X-Mail2News-Path: genesis.demon.co.uk