Thread View: comp.sys.mac.programmer.codewarrior
10 messages
10 total messages
Started by G. Ruth Hammond
Thu, 14 Dec 1995 12:06
ANSI standards
Author: G. Ruth Hammond
Date: Thu, 14 Dec 1995 12:06
Date: Thu, 14 Dec 1995 12:06
23 lines
1488 bytes
1488 bytes
Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void main(void) and it compiles ok, but using DEC C++ on an alpha it insists on int main(void) and won't compile otherwise. CodeWarrior won't compile it with an int main (void), it gives link errors. My code is a very simple model of a 4 stroke engine using an "engine" class and reading characteristic data from a disk file, and terminating with exit() hmmm... I'm using the standard ANSI stationery on CodeWarrior7 with the preferences set to ANSI strict and DEC C++ Version V1.3A-0 on OpenVMS AXP version V6.1-1H1 which one is the correct ANSI standard? and is there a way to ensure my source will compile without modification on both platforms (maybe with #ifdef?) -- * Guy Ruth Hammond - cold, tired, lonely, hungry and depressed * * Undergraduate at University College London, Mechanical Engineering * * hammond_g@meng.ucl.ac.uk | http://www.ucl.ac.uk/~zcemm23/home.html * * Clear the DECs, it's time for action! *
Re: ANSI standards
Author: MW Ron
Date: Thu, 14 Dec 1995 19:29
Date: Thu, 14 Dec 1995 19:29
32 lines
1627 bytes
1627 bytes
hammond_g@drkclu.meng.ucl.ac.uk (G. Ruth Hammond) writes: >Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void main(void) >and it compiles ok, but using DEC C++ on an alpha it insists on int main(void) >and won't compile otherwise. CodeWarrior won't compile it with an int main >(void), it gives link errors. >-- % snip % -- >which one is the correct ANSI standard? and is there a way to ensure my source >will compile without modification on both platforms (maybe with #ifdef?) Hi Guy there is no reason for this not to work returning an integer is the SOP in C++ so much so that you don't even declare it usually just write main(). I have a feeling the problemis you have selected to treat all warnings as an error and do not have a return 0; as your last line in main(). Many compilers will return a zero for you from main() [ it might be called for in the standard, but I am not sure ] so your DEC compiler probably does this for you. If this is not the problem let me know, but this should not be a problem. Ron METROWERKS Ron Liechty "Software at Work" MWRon@metrowerks.com
Re: ANSI standards
Author: Dietmar Kuehl
Date: Thu, 14 Dec 1995 20:54
Date: Thu, 14 Dec 1995 20:54
22 lines
1512 bytes
1512 bytes
Hi, G. Ruth Hammond (hammond_g@drkclu.meng.ucl.ac.uk) wrote: : Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void main(void) : and it compiles ok, but using DEC C++ on an alpha it insists on int main(void) : and won't compile otherwise. CodeWarrior won't compile it with an int main : (void), it gives link errors. My code is a very simple model of a 4 stroke : engine using an "engine" class and reading characteristic data from a disk : file, and terminating with exit() The two portable declarations of 'main()' are (3.6.1, basic.start.main, verse 2 of the April DWP): int main() int main(int ac, char *av[]) All other declarations of 'main()' are non-portable but every conforming C++ (or C) compiler has to provide at least the two mentioned above. -- dietmar.kuehl@uni-konstanz.de http://www.informatik.uni-konstanz.de/~kuehl I am a realistic optimist - that's why I appear to be slightly pessimistic
Re: ANSI standards
Author: Lou Pecora
Date: Fri, 15 Dec 1995 01:27
Date: Fri, 15 Dec 1995 01:27
39 lines
1953 bytes
1953 bytes
In article <4aptvk$q7b@newsbf02.news.aol.com>, mwron@aol.com (MW Ron) wrote: > hammond_g@drkclu.meng.ucl.ac.uk (G. Ruth Hammond) writes: > > >Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void > main(void) > >and it compiles ok, but using DEC C++ on an alpha it insists on int > main(void) > >and won't compile otherwise. CodeWarrior won't compile it with an int > main > >(void), it gives link errors. > >-- % snip % -- > >which one is the correct ANSI standard? and is there a way to ensure my > source > >will compile without modification on both platforms (maybe with #ifdef?) > > Hi Guy there is no reason for this not to work returning an integer is the > SOP in C++ so much so that you don't even declare it usually just write > main(). I have a feeling the problemis you have selected to treat all > warnings as an error and do not have a return 0; as your last line in > main(). > > Many compilers will return a zero for you from main() [ it might be > called for in the standard, but I am not sure ] so your DEC compiler > probably does this for you. > > If this is not the problem let me know, but this should not be a problem. Yeah, I've done int main (whatever) with return 1 or 0 and it works fine. -- Lou Pecora code 6341 Naval Research Lab Washington DC 20375 USA pecora@zoltar.nrl.navy.mil /* My views are not those of the U.S. Navy. If you want their views, you have to go to war. */
Re: ANSI standards
Author: Fletcher Sandbeck
Date: Fri, 15 Dec 1995 05:14
Date: Fri, 15 Dec 1995 05:14
10 lines
882 bytes
882 bytes
I don't which is ANSI, but both make sense. The DEC is expecting an error result from every run program and the Mac is not. It seems to me that they are both being a little too fascist for their own good (the DEC should have a standard return if main returns void and the Mac should just chuck out main's result). but...I'd use an #ifdef and just chalk it up to compiler weirdness. [fletcher]
Re: ANSI standards
Author: williamt
Date: Mon, 18 Dec 1995 03:16
Date: Mon, 18 Dec 1995 03:16
21 lines
1240 bytes
1240 bytes
hammond_g@drkclu.meng.ucl.ac.uk (G. Ruth Hammond) wrote:
>
>Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void main(void)
>and it compiles ok, but using DEC C++ on an alpha it insists on int main(void)
>and won't compile otherwise. ...
>which one is the correct ANSI standard? and is there a way to ensure my source
>will compile without modification on both platforms (maybe with #ifdef?)
I don't recall what the ANSI standard is, I'd suspect void main(void);...
All Metrowerks compilers declare __MWERKS__ so you could #ifdef on that:
#ifdef __MWERKS__
void main(void)
#else
int main(void)
#endif
{
... /* main stuff */
}
Re: ANSI standards
Author: Ari Lukumies
Date: Mon, 18 Dec 1995 13:57
Date: Mon, 18 Dec 1995 13:57
45 lines
1919 bytes
1919 bytes
The ANSI standard states these formats for main:
int main(int argc, char **argv, char **env);
int main(int argc, char **argv);
int main(void);
Or you can use void as the return type. Some compilers make
you explicitly state that you want ANSI compilation (eg,
cc in HP-UX uses the flag -Aa), otherwise they don't recognize
the ANSI prototypes, in which case you'd use
int main()
int main(argc, argv) int argc; char **argv; { ... }
or just plain
main()
variants without the return type.
ANSI declares that there should be a compiler predefined
identifier __STDC__ you can use for checking if the compiler
is ANSI-compliant:
#ifdef __STDC__
...
#else
...
#endif
Unfortunately, ANSI standard contains more than just the
compiler, which has lead to many misuses considering the other
parts of the compiling system, mainly the runtime libraries
and header file names/functions. Many compiler vendors _do_
use the __STDC__ identifier but to only mark their _compiler_
as ANSI-compliant; they do not use it to tell that their
libraries are also ANSI-compliant, and generally they are not.
So I suggest you just go and test each and every
compiler/platform and use some #define of your own to
distinguish between them.
Ari Lukumies
--
All my opinions are mine and mine alone.
Re: ANSI standards
Author: Alun Champion
Date: Mon, 18 Dec 1995 18:30
Date: Mon, 18 Dec 1995 18:30
15 lines
1004 bytes
1004 bytes
In article <30D57365.212D@cmt.lpr.mail.carel.fi> Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes: : The ANSI standard states these formats for main: : int main(int argc, char **argv, char **env); : int main(int argc, char **argv); : int main(void); Actually the ANSI standard only states the last two formats but suggests implementation defined optional additional parameters to be added on the end. Regards -A. -- | A.Champion |
Re: ANSI standards
Author: James Kanze US/ESC 60/3/141 #407...
Date: Mon, 18 Dec 1995 19:21
Date: Mon, 18 Dec 1995 19:21
91 lines
3845 bytes
3845 bytes
In article <30D57365.212D@cmt.lpr.mail.carel.fi> Ari Lukumies
<aril@cmt.lpr.mail.carel.fi> writes:
|> The ANSI standard states these formats for main:
|> int main(int argc, char **argv, char **env);
|> int main(int argc, char **argv);
|> int main(void);
|> Or you can use void as the return type.
Could you please quote chapter and verse. My draft standard states
that "An implementation shall allow both of the following definitions
for main:
int main() { /* ... */ }
and
int main( int argc , char* argv[] ) { /* ... */ }
Nothing about a third parameter, and nothing about void. This
represents no change with regards to C.
An implementation may allow any additional forms it wishes. Posix, I
believe, requires also supporting the form:
int main( int argc , char* argv[] , char* env[] ) // ...
(Since the original posting was cross-posted to a Mac group, however,
I presume that the poster is not particularly interested in Posix
extensions to C.)
|> Some compilers make
|> you explicitly state that you want ANSI compilation (eg,
|> cc in HP-UX uses the flag -Aa), otherwise they don't recognize
|> the ANSI prototypes, in which case you'd use
|> int main()
|> int main(argc, argv) int argc; char **argv; { ... }
|> or just plain
|> main()
|> variants without the return type.
You seem to be confusing languages. In C++, the first declaration
above is exactly the same as ``int main( void )'', and the second is
illegal.
The third is also illegal in C++, and will probably be deprecated in
the next C standard.
|> ANSI declares that there should be a compiler predefined
|> identifier __STDC__ you can use for checking if the compiler
|> is ANSI-compliant:
|> #ifdef __STDC__
|> ...
|> #else
|> ...
|> #endif
Again, to quote the draft standard: "Whether __STDC__ is defined, and
if so, what its value is, are implementation defined."
The C standard requires conformant compilers to define __STDC__ to 1.
In practice, this has not been particularly effective, since of
course, the C standard cannot say anything about non-conformant
compilers, and many of them also define __STDC__.
|> Unfortunately, ANSI standard contains more than just the
|> compiler, which has lead to many misuses considering the other
|> parts of the compiling system, mainly the runtime libraries
|> and header file names/functions. Many compiler vendors _do_
|> use the __STDC__ identifier but to only mark their _compiler_
|> as ANSI-compliant; they do not use it to tell that their
|> libraries are also ANSI-compliant, and generally they are not.
|> So I suggest you just go and test each and every
|> compiler/platform and use some #define of your own to
|> distinguish between them.
This is especially important given the number of recent features, that
are not supported by most current compilers. In practice, I would
recommend a #define per missing feature.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
-- A la recherche d'une activité dans une region francophone
Re: ANSI standards
Author: David H. Thornley
Date: Tue, 19 Dec 1995 17:20
Date: Tue, 19 Dec 1995 17:20
23 lines
1510 bytes
1510 bytes
In article <4b2me3$a8c@news.aloha.com>, <williamt@aloha.com> wrote:
>hammond_g@drkclu.meng.ucl.ac.uk (G. Ruth Hammond) wrote:
>>
>>Using Metrowerks CodeWarrior C++ on my LC475 I declare main as void main(void)
>>and it compiles ok, but using DEC C++ on an alpha it insists on int main(void)
>>and won't compile otherwise. ...
>
>I don't recall what the ANSI standard is, I'd suspect void main(void);...
>
It's int main(whatever), and that works in Metrowerks. There must be
some other problem somewhere.
>All Metrowerks compilers declare __MWERKS__ so you could #ifdef on that:
>
>[conditional code deleted]
I'd rather try finding the actual problem and fixing it rather than
trying to spoof the only compiler that complains with nonstandard code.
--
David H. Thornley, known to the Wise as thornley@cs.umn.edu
Disclaimer: These are not the opinions of the University of Minnesota,
its Regents, faculty, staff, students, or squirrels.
Datclaimer: Well, maybe the squirrels. They're pretty smart.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads