468,491 Members | 2,033 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

return value of main

Hi,

the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

Regards,
Chris
Aug 2 '06 #1
25 4133
Christian Christmann wrote:
Hi,

the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
The latter.

Try compiling void main(){} with gcc -Wall -ansi -pedantic.

--
Ian Collins.
Aug 2 '06 #2
? "Christian Christmann" <pl*****@yahoo.de?????? ??? ??????
news:pa****************************@yahoo.de...
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
Check questions 11.12a-11.15 of the C faq
(http://c-faq.com/ansi/).

Previous ANSI-C standards did not define void as return type.

--
Papastefanos Serafeim
Aug 2 '06 #3
Papastefanos Serafeim wrote:
? "Christian Christmann" <pl*****@yahoo.de?????? ??? ??????
news:pa****************************@yahoo.de...
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

Check questions 11.12a-11.15 of the C faq
(http://c-faq.com/ansi/).
Previous ANSI-C standards did not define void as return type.
Is this just sloppy posting, in which you meant "No ANSI C standard has
defined void as the return type for main", or is it
Jacob's disease of trying to take away features that have been part of C
since the *first* ANSI C standard (1989) striking again?

Check 3.1.2.5 of the 1989 C standard for the void type.

Aug 2 '06 #4
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
It's pure ignorance. No C standard has ever defined main as returning
void.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 2 '06 #5
Christian Christmann said:
Hi,

the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
No, never, but see below.
or is this issue just a lack of C knowledge?
Mostly, yes.

The void type has never been a correct return type for main except in the
following circumstances, which also cover all other possible return types
(double main, struct tm main, union myunion main, etc):

1) in C90 and C99, if the implementation is freestanding and documents the
type in question as the appropriate return type for the entry point (which
might not even be called main);
2) in C99 *only*, if the implementation explicitly documents the return type
in question as being supported.

In each case, returning a value of a type other than int from main means
that your program is not portable to implementations that do not document
and support such a return type.

So, as with so much in life, the simple answer doesn't quite tell the full
story.

For maximal portability, use int as the type of your return value from main.
The only case where this doesn't work is where your (necessarily
freestanding) implementation specifically /requires/ you to do otherwise,
in which case your program - or at least the entry point part of it - isn't
going to be portable anyway.

A classic example of a freestanding implementation is Visual C when used in
the normal way to compile Windows programs - the entry point is not main,
but WinMain, and therefore the implementation *must* be freestanding! :-)

Ironically for a company that has done so much to spread the void main myth,
Microsoft's WinMain is required to return int!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 2 '06 #6
Richard Heathfield <in*****@invalid.invalidwrites:
Christian Christmann said:
>the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type

No, never, but see below.
>or is this issue just a lack of C knowledge?

Mostly, yes.

The void type has never been a correct return type for main except in the
following circumstances, which also cover all other possible return types
(double main, struct tm main, union myunion main, etc):

1) in C90 and C99, if the implementation is freestanding and documents the
type in question as the appropriate return type for the entry point (which
might not even be called main);
2) in C99 *only*, if the implementation explicitly documents the return type
in question as being supported.
[...]

Both the C90 and C99 standards have the following:

A conforming implementation may have extensions (including
additional library functions), provided they do not alter the
behavior of any strictly conforming program.

Allowing "void main(void)" would be such an extension. (Because of
this, C99 5.1.2.2.1's explicit permission to allow other forms of main
is, I believe, redundant.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 2 '06 #7
Keith Thompson <ks***@mib.orgwrote:
Allowing "void main(void)" would be such an extension. (Because of
this, C99 5.1.2.2.1's explicit permission to allow other forms of main
is, I believe, redundant.)
Redundant, but also perhaps yet necessary, given the relative
abundance of implementations offering that extension and the
consequent confusion.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 2 '06 #8
Martin Ambuhl wrote:
Papastefanos Serafeim wrote:
? "Christian Christmann" <pl*****@yahoo.de?????? ??? ??????
news:pa****************************@yahoo.de...
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
Check questions 11.12a-11.15 of the C faq
(http://c-faq.com/ansi/).
Previous ANSI-C standards did not define void as return type.

Is this just sloppy posting, in which you meant "No ANSI C standard has
defined void as the return type for main", or is it
Jacob's disease of trying to take away features that have been part of C
since the *first* ANSI C standard (1989) striking again?
Given the context offered by the quoted material, the meaning of
Papastefanos's statement is clear. The same cannot be said for
your statement about "Jacob's disease."

Aug 2 '06 #9
In article <11**********************@m79g2000cwm.googlegroups .com>,
Dingo <di*************@aol.comwrote:
....
>Given the context offered by the quoted material, the meaning of
Papastefanos's statement is clear. The same cannot be said for
your statement about "Jacob's disease."
Shhhh. If you disagree with a "regular", you risk being branded a,
gasp!, "troll".

Aug 2 '06 #10
Kenny McCormack said:
In article <11**********************@m79g2000cwm.googlegroups .com>,
Dingo <di*************@aol.comwrote:
...
>>Given the context offered by the quoted material, the meaning of
Papastefanos's statement is clear. The same cannot be said for
your statement about "Jacob's disease."

Shhhh. If you disagree with a "regular", you risk being branded a,
gasp!, "troll".
Nonsense. I disagree with regulars a heck of a lot, and nobody with a brain
ever called me a troll.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 2 '06 #11
In article <3-******************************@bt.com>,
Richard Heathfield <in*****@invalid.invalidwrote:
>Kenny McCormack said:
>In article <11**********************@m79g2000cwm.googlegroups .com>,
Dingo <di*************@aol.comwrote:
...
>>>Given the context offered by the quoted material, the meaning of
Papastefanos's statement is clear. The same cannot be said for
your statement about "Jacob's disease."

Shhhh. If you disagree with a "regular", you risk being branded a,
gasp!, "troll".

Nonsense. I disagree with regulars a heck of a lot, and nobody with a brain
ever called me a troll.
I've never seen you disagree with them on a fundamental aspect of canon.
You are clearly in the fold.

Aug 2 '06 #12
In article <ea**********@news.xmission.com>,
Kenny McCormack <ga*****@xmission.xmission.comwrote:
>I've never seen you disagree with them on a fundamental aspect of canon.
You are clearly in the fold.
Canon... let's see, that would be:

2) I am the ISO C, thine Standards; Thou shalt have no other Standards
before me.

3) The internal organs of compilers are Icky, and Thou shalt not
reveal them here, for We art Squeemish.

4) Thou shalt not rely on unacknowledged UB or IB.

5) Thou shalt not demand answers to thine homework.

6) Thou shalt not remove attributions of quotations.

7) Thou shalt acknowledge the practical difficulties of using C99.

1) Thou shalt not top-post.

--
Prototypes are supertypes of their clones. -- maplesoft
Aug 2 '06 #13
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <ea**********@news.xmission.com>,
Kenny McCormack <ga*****@xmission.xmission.comwrote:
[snip]
>
Canon... let's see, that would be:

2) I am the ISO C, thine Standards; Thou shalt have no other Standards
before me.

3) The internal organs of compilers are Icky, and Thou shalt not
reveal them here, for We art Squeemish.

4) Thou shalt not rely on unacknowledged UB or IB.

5) Thou shalt not demand answers to thine homework.

6) Thou shalt not remove attributions of quotations.

7) Thou shalt acknowledge the practical difficulties of using C99.

1) Thou shalt not top-post.
0) Thou shalt not feed the trolls.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 2 '06 #14

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

It's pure ignorance. No C standard has ever defined main as returning
void.
Chris Torek has covered this in the past... 'void main' predates all formal
C standards except K&R (1979). The links below indicate 'void' was for the
PCC compiler for 4.1c BSD (about 1981). It is a logical derivative (not
"pure ignorance") from the more common method of defining the void type for
early C compilers that were lacking 'void':

#define void int

If you search the Usenet archives via Google Groups advanced search from
1981-1989, you'll see that people struggled to find a good way to define
void:

#define void int
#define void (char *(0))
#define void (void)
etc...
FYI, the first Google Usenet msg use of 'void main' was in 1984:
http://groups.google.com/group/net.l...bb23c5ab?hl=en

FYI, the first Google Usenet use of '#define void' was in 1983:
http://groups.google.com/group/net.s...7c30168f?hl=en

FYI, the first Google Usent use of 'void' was in 1982:
http://groups.google.com/group/net.b...f84d6835?hl=en

Chris Torek on void type:
http://groups.google.com/group/comp....6057ce7c?hl=en

Probable source of Chris' comments about 'void' (i.e., PCC compiler for
4.1c BSD circa 1981):
http://www.faqs.org/docs/artu/c_evolution.html

Rod Pemberton

Aug 3 '06 #15

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

It's pure ignorance. No C standard has ever defined main as returning
void.
Chris Torek has covered this in the past... 'void main' predates all formal
C standards except K&R (1979). The links below indicate 'void' was for the
PCC compiler for 4.1c BSD (about 1981). It is a logical derivative (not
"pure ignorance") from the more common method of defining the void type for
early C compilers that were lacking 'void':

#define void int

If you search the Usenet archives via Google Groups advanced search from
1981-1989, you'll see that people struggled to find a good way to define
void:

#define void int
#define void (char *(0))
#define void (void)
etc...
FYI, the first Google Usenet msg use of 'void main' was in 1984:
http://groups.google.com/group/net.l...bb23c5ab?hl=en

FYI, the first Google Usenet use of '#define void' was in 1983:
http://groups.google.com/group/net.s...7c30168f?hl=en

FYI, the first Google Usent use of 'void' was in 1982:
http://groups.google.com/group/net.b...f84d6835?hl=en

Chris Torek on void type:
http://groups.google.com/group/comp....6057ce7c?hl=en

Probable source of Chris' comments about 'void' (i.e., PCC compiler for
4.1c BSD circa 1981):
http://www.faqs.org/docs/artu/c_evolution.html

Rod Pemberton



Aug 3 '06 #16
In article <11*************@dscnews2.dcccd.edu"Rod Pemberton" <do*********@bitfoad.cmmwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.
>
Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?
It's pure ignorance. No C standard has ever defined main as returning
void.

Chris Torek has covered this in the past... 'void main' predates all formal
C standards except K&R (1979). The links below indicate 'void' was for the
PCC compiler for 4.1c BSD (about 1981).
Read that it is *not* about "void main"...
FYI, the first Google Usenet msg use of 'void main' was in 1984:
http://groups.google.com/group/net.l...bb23c5ab?hl=en
But was that correct?
FYI, the first Google Usenet use of '#define void' was in 1983:
http://groups.google.com/group/net.s...7c30168f?hl=en
That is #define VOID (char *)0, defining a null pointer.
FYI, the first Google Usent use of 'void' was in 1982:
http://groups.google.com/group/net.b...f84d6835?hl=en
Yup, common use, casting the return of a function to void, even at that
time (to keep lint happy).

So, most of your references are about the type void, not about "void main".
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 3 '06 #17
"Rod Pemberton" <do*********@bitfoad.cmmwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.

Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

It's pure ignorance. No C standard has ever defined main as returning
void.

Chris Torek has covered this in the past... 'void main' predates all formal
C standards except K&R (1979). The links below indicate 'void' was for the
PCC compiler for 4.1c BSD (about 1981). It is a logical derivative (not
"pure ignorance") from the more common method of defining the void type for
early C compilers that were lacking 'void':

#define void int

If you search the Usenet archives via Google Groups advanced search from
1981-1989, you'll see that people struggled to find a good way to define
void:

#define void int
#define void (char *(0))
#define void (void)
etc...
Only the first of these makes any sense, as far as I can tell.
FYI, the first Google Usenet msg use of 'void main' was in 1984:
http://groups.google.com/group/net.l...bb23c5ab?hl=en

FYI, the first Google Usenet use of '#define void' was in 1983:
http://groups.google.com/group/net.s...7c30168f?hl=en

FYI, the first Google Usent use of 'void' was in 1982:
http://groups.google.com/group/net.b...f84d6835?hl=en

Chris Torek on void type:
http://groups.google.com/group/comp....6057ce7c?hl=en

Probable source of Chris' comments about 'void' (i.e., PCC compiler for
4.1c BSD circa 1981):
http://www.faqs.org/docs/artu/c_evolution.html
The "Chris Torek on void type" article you cited indicates that void
itself is older than I had realized; apparently it appeared around
1979, about the same time as "enum". "void*", on the other hand, was
an invention of the ANSI committee.

And as long as we're citing Chris Torek, here's something he wrote
2000-11-02,
<http://groups.google.com/group/comp.lang.c/msg/a39611f02ed05852?hl=en&>:
[...]
| I believe authors use "void main" primarily out of ignorance.
|
| There are lots of complicated rules you can fiddle with, like
| investigating exactly how your particular compiler and/or OS work,
| whether your program will ever be run from a batch file or makefile,
| and so on. But there is one very simple rule that always works:
|
| If you write "int main", and return 0, your program *will* work
| (provided you have no other bugs). If you write "void main", your
| program *might* work; but if you use "int main", it *will* work.
| Rather than worrying about when and where "void main" might work,
| why not use the one that is absolutely, positively, 100% sure?

Admittedly he was talking about current C, not the historical context.

But most of the reference you cite talk about the void type, not
specifically about "void main". Apparently ignorant uses of "void
main" are also older than I realized, but I see nothing indicating
that it was ever correct. Unless you can cite a standard or some
pre-ANSI de facto standard that says "void main" is valid, my point
stands.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 3 '06 #18

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
But most of the reference you cite talk about the void type, not
specifically about "void main". Apparently ignorant uses of "void
main" are also older than I realized, but I see nothing indicating
that it was ever correct. Unless you can cite a standard or some
pre-ANSI de facto standard that says "void main" is valid, my point
stands.
'int' is a type-specifier. 'void' is a type-specifier. 'void main' has
'void' used as a type-specifier instead of 'int' as a type-specifier. So,
the key issue is how was 'void' used as a type-specifier _before_ (i.e.,
from 1979-80) it was standardized as part of the C language. As I
indicated, 1) 'void', on compilers that didn't supply it, was defined to a
valid type-specifier, usually 'int' and 2) it was added to an important Unix
compiler of the era PCC. If programmers of the era understood that 'void'
was usually an alias for 'int', it wouldn't be an ignorant use, would it?
It would only be ignorant if they continued to use it long after C90.
Rod Pemberton
Aug 3 '06 #19

"Dik T. Winter" <Di********@cwi.nlwrote in message
news:J3********@cwi.nl...
In article <11*************@dscnews2.dcccd.edu"Rod Pemberton"
<do*********@bitfoad.cmmwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.
>
Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

It's pure ignorance. No C standard has ever defined main as
returning
void.
>
Chris Torek has covered this in the past... 'void main' predates all
formal
C standards except K&R (1979). The links below indicate 'void' was for
the
PCC compiler for 4.1c BSD (about 1981).

Read that it is *not* about "void main"...
....
So, most of your references are about the type void, not about "void
main".

You could search for other slightly later references too. I just posted the
earliest I could find. See also reply to KT.

Rod Pemberton
Aug 3 '06 #20
"Rod Pemberton" <do*********@bitfoad.cmmwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>But most of the reference you cite talk about the void type, not
specifically about "void main". Apparently ignorant uses of "void
main" are also older than I realized, but I see nothing indicating
that it was ever correct. Unless you can cite a standard or some
pre-ANSI de facto standard that says "void main" is valid, my point
stands.

'int' is a type-specifier. 'void' is a type-specifier. 'void main' has
'void' used as a type-specifier instead of 'int' as a type-specifier. So,
the key issue is how was 'void' used as a type-specifier _before_ (i.e.,
from 1979-80) it was standardized as part of the C language. As I
indicated, 1) 'void', on compilers that didn't supply it, was defined to a
valid type-specifier, usually 'int' and 2) it was added to an important Unix
compiler of the era PCC. If programmers of the era understood that 'void'
was usually an alias for 'int', it wouldn't be an ignorant use, would it?
It would only be ignorant if they continued to use it long after C90.
Programmers of that era would have understood that "void", when used
as a return type, indicates that the function doesn't return a value,
but that the word could be aliased to "int" for compilers that didn't
yet directly support "void".

Declaring
void main()
is and was no more sensible than declaring
void n = 42;

The usual way to declare main back in the old days was simply:
main()
which was used in the examples in K&R1.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 3 '06 #21
"Rod Pemberton" <do*********@bitfoad.cmmwrites:
"Dik T. Winter" <Di********@cwi.nlwrote in message
news:J3********@cwi.nl...
>In article <11*************@dscnews2.dcccd.edu"Rod Pemberton"
<do*********@bitfoad.cmmwrites:
> "Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Christian Christmann <pl*****@yahoo.dewrites:
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.
>
Did previous ANSI-C standards defined "void" as return type
or is this issue just a lack of C knowledge?

It's pure ignorance. No C standard has ever defined main as
returning void.

Chris Torek has covered this in the past... 'void main'
predates all formal C standards except K&R (1979). The links
below indicate 'void' was for the PCC compiler for 4.1c BSD
(about 1981).

Read that it is *not* about "void main"...
...
>So, most of your references are about the type void, not about
"void main".

You could search for other slightly later references too. I just
posted the earliest I could find. See also reply to KT.
The point is that the references you posted *don't support your
claim*, which was specifically about "void main", not just "void".

If you want to dig up references that actually do support your claim,
feel free to do so.

You can post all the examples you like of people *using* "void main";
that doesn't demonstrate that those uses are based on anything other
than ignorance. If you can find any references that support your
claim that using "void main" was based on anything other than
ignorance, I'd be interested in seeing them.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 3 '06 #22
In article <11*************@dscnews2.dcccd.edu"Rod Pemberton" <do*********@bitfoad.cmmwrites:
....
'int' is a type-specifier. 'void' is a type-specifier. 'void main' has
'void' used as a type-specifier instead of 'int' as a type-specifier.
Yes, and 'double main' has 'double' as a type-specifier instead of 'int'.
And 'struct {float re, im;} main' has again some other type-specifier.
What is the relevance?
So,
the key issue is how was 'void' used as a type-specifier _before_ (i.e.,
from 1979-80) it was standardized as part of the C language.
Precisely as I wrote. To shut up lint complaining about unused function
returns.
As I
indicated, 1) 'void', on compilers that didn't supply it, was defined to a
valid type-specifier, usually 'int'
Yes, because you wanted to compile.
2) it was added to an important Unix
compiler of the era PCC.
Indeed, to be able to shut up lint.
If programmers of the era understood that 'void'
was usually an alias for 'int',
If they understood that, they did not understand it. 'void' as an alias
for 'int' would not shut up lint.
it wouldn't be an ignorant use, would it?
It would be ignorance, not knowing the reason 'void' was added.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 3 '06 #23
In most freestanding embedded systems main is called but never exited. void main (void) makes sense. If main returns a value where is the result going to be sent?

In most automotive systems for example processors either never stop or run without exiting all of the time the vehicle is on. Most automotive processors have a single standalone application almost uniformly written in C.

w..
Aug 3 '06 #24
Walter Banks <wa****@bytecraft.comwrites:
In most freestanding embedded systems main is called but never
exited. void main (void) makes sense. If main returns a value where
is the result going to be sent?

In most automotive systems for example processors either never stop
or run without exiting all of the time the vehicle is on. Most
automotive processors have a single standalone application almost
uniformly written in C.
Please provide context when posting a followup.

You're right, I've been ignoring freestanding implementations. (We
tend to do that here, probably more than we should.)

C99 5.1.2.1p1:

In a freestanding environment (in which C program execution may
take place without any benefit of an operating system), the name
and type of the function called at program startup are
implementation-defined.

So in that context,
void main(void)
is as legitimate as
int main(void)
which is as legitimate as
unsigned long _Startup(int foobar)
The implementation gets to decide how the startup function is to be
declared. And if the program never returns to the environment (or
there's no environment for it to return to), then "void main(void)" is
very likely to be the most sensible way to define it.

So let me amend my previous comments to refer only to hosted
environments.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 4 '06 #25
>In article <11*************@dscnews2.dcccd.edu"Rod Pemberton"
><do*********@bitfoad.cmmwrites:
>Chris Torek has covered this in the past... 'void main' predates all formal
C standards except K&R (1979). The links below indicate 'void' was for the
PCC compiler for 4.1c BSD (about 1981).
In article <J3********@cwi.nl>, Dik T. Winter <Di********@cwi.nlwrote:
>Read [the link] it is *not* about "void main"...
Indeed, it was about "void" itself. Of course if "void" were
simply "#define"d to "int", one could write:

#define void int
void main() { return 42; }

and the like; but this is equivalent to writing:

#define purple int
purple main() { return 42; }

Neither one is particularly sensible. If main() is to return an
"int" value, one might as well write "int main()" (or, in modern
C, "int main(void)"). (Of course one can add argc and argv as
usual.)

As an aside, "void" and PCC (Steve Johnson's Portable C Compiler)
long predate 4.1cBSD as well. The original BSD distributions were
on PDP-11s and related to V6 and V7 (Ken Thompson spent some time
at Berkeley, if I remember right) and at some point acquired the
PDP-11 version of PCC; the first VAX BSD distributions were derived
from 32V, which was sort of an offshoot of PWB Unix, and used PCC
from the beginning. Hence 3.0BSD, 4.0BSD, 4.1BSD, and both the
"a" and "b" versions of 4.1BSD (4.1a and 4.1b) used PCC along with
4.1c. The "a" through "c" versions were just various snapshots
along the way to the original 4.2BSD release, which was the first
"non-beta" release of sockets, fast file system, and so on.

(32V PCC had 8-character symbols as usual; I think it was somewhere
between 3.0 and 4.0BSD that Berkeley modified the compilers and
linkers to support longer names -- up to 1023 characters -- although
that may have been as late as 4.1BSD. This was probably mostly
for Berkeley Pascal, which strung nested function names together
with underscores. "Stabs" symbolic debugging was shoehorned in
shortly afterward, with Mark Linton's "dbx" debugger, which was
perhaps the first symbolic debugger for C code, although it was
originally part of the whole Pascal system.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Aug 7 '06 #26

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Piotr | last post: by
32 posts views Thread by Mike Machuidel | last post: by
20 posts views Thread by lovecreatesbeauty | last post: by
37 posts views Thread by Army1987 | last post: by
17 posts views Thread by Sara | last post: by
27 posts views Thread by junky_fellow | last post: by
46 posts views Thread by Bill Cunningham | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.