🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #1177

Re: Pascal program works but not C program!

#1177
From: Peter Seebach
Date: Thu, 11 Jan 1996 23:39
52 lines
3273 bytes
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 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;".

>So if you find a compiler that won't accept "int main(int, char **)",
>you have grounds for a complaint.  If your compiler won't accept
>"void main(int, char **, char **)", tough.  You're SOL unless there
>is some other standard (like POSIX, perhaps) that requires it -- then
>your program is limited to systems covered by that other standard.

Exactly; although, as I recall, POSIX does not support or encourage void
main, and envp has been deprecated in favor of the extern char *[]
environ.

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

-s
-- 
Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
Technical Details
Message-ID: <4d4742$n50@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4cdpr2$psi@lugb.latrobe.edu.au> <4cp3vc$8nh@brahms.tfi.be> <4cpqt6$9r8@solutions.solon.com> <4d3scf$4uk@gap.cco.caltech.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: seebs@solutions.solon.com (Peter Seebach)
Newsgroups: alt.msdos.programmer,comp.lang.c
Subject: Re: Pascal program works but not C program!
Date: 11 Jan 1996 17:39:46 -0600
Organization: Usenet Fact Police (Undercover)
Message-ID: <4d4742$n50@solutions.solon.com>
References: <4cdpr2$psi@lugb.latrobe.edu.au> <4cp3vc$8nh@brahms.tfi.be> <4cpqt6$9r8@solutions.solon.com> <4d3scf$4uk@gap.cco.caltech.edu>
NNTP-Posting-Host: solutions.solon.com