473,395 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

main without a return statement

Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }

return TRUE;
}

my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,
Amish

Nov 7 '07 #1
13 2248
axr0284 wrote On 11/07/07 10:27,:
Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }

return TRUE;
}

my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,
Yes, you can remove it.

(Incidentally, TRUE looks like a strange value to
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

--
Er*********@sun.com
Nov 7 '07 #2
On Nov 7, 11:23 am, Eric Sosman <Eric.Sos...@sun.comwrote:
axr0284 wrote On 11/07/07 10:27,:
Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }
return TRUE;
}
my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,

Yes, you can remove it.

(Incidentally, TRUE looks like a strange value to
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

--
Eric.Sos...@sun.com
Forgot to added the #define TRUE 1
Thanks for the answer

Nov 7 '07 #3
axr0284 wrote:
On Nov 7, 11:23 am, Eric Sosman <Eric.Sos...@sun.comwrote:
>axr0284 wrote On 11/07/07 10:27,:
>>Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }
return TRUE;
}
my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,
Yes, you can remove it.

(Incidentally, TRUE looks like a strange value to
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

--
Eric.Sos...@sun.com

Forgot to added the #define TRUE 1
Thanks for the answer
1 is not among the standard return values from main. The three with
mentioned in the standard are, as Eric Sosman wrote, 0, EXIT_SUCCESS,
and EXIT_FAILURE.

Nov 7 '07 #4
axr0284 wrote:
On Nov 7, 11:23 am, Eric Sosman <Eric.Sos...@sun.comwrote:
....
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

--
Eric.Sos...@sun.com

Forgot to added the #define TRUE 1
Thanks for the answer
Keep in mind that the only fully-portable return values are the ones
Eric listed above, and none of them are guaranteed to be equal to 1.

Nov 7 '07 #5
axr0284 wrote:
On Nov 7, 11:23 am, Eric Sosman <Eric.Sos...@sun.comwrote:
>axr0284 wrote On 11/07/07 10:27,:
>>int main(void)
{
while(TRUE) { ... }
return TRUE;
}
(Incidentally, TRUE looks like a strange value to
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

Forgot to added the #define TRUE 1
Thanks for the answer
Please don't quote signatures.

Note that on a great many systems, returning 1 will indicate program
failure. If you have no compelling reason not to, only return
EXIT_SUCCESS, EXIT_FAILURE, or zero. Zero is equivalent to EXIT_SUCCESS.

--
Philip Potter pgp <atdoc.ic.ac.uk
Nov 7 '07 #6
On Wed, 07 Nov 2007 15:27:07 -0000, axr0284 <ax*****@yahoo.comwrote:
>Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }

return TRUE;
}

my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,
Is there no break statement in the while loop? If that return
statement cannot be reached, how does main ever terminate? Does main
terminate or is your code for an embedded system?

TRUE is obviously non-zero and probably 1. It is not a portable value
to pass back to the operating system. At the point main does
terminate (if any), what value do you pass back to the operating
system.
Remove del for email
Nov 8 '07 #7
"axr0284" <ax*****@yahoo.coma écrit dans le message de news:
11*********************@o80g2000hse.googlegroups.c om...
On Nov 7, 11:23 am, Eric Sosman <Eric.Sos...@sun.comwrote:
>axr0284 wrote On 11/07/07 10:27,:
Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }
return TRUE;
}
my question is since the return TRUE is never reached, can I remove
it. The compiler (VDSP 5.0) is complaining about the non reachability
in this case. When I remove it, it compiles without warning. Thanks,

Yes, you can remove it.

(Incidentally, TRUE looks like a strange value to
return from main(). The only fully-portable return
values are EXIT_SUCCESS, EXIT_FAILURE, and zero.)

--
Eric.Sos...@sun.com

Forgot to added the #define TRUE 1
Thanks for the answer
TRUE is not really needed, nor welcome, the classic idiom for this kind of
loop is

for (;;) { ... }

--
Chqrlie.
Nov 9 '07 #8
"Charlie Gordon" <ne**@chqrlie.orgwrites:
[...]
TRUE is not really needed, nor welcome, the classic idiom for this kind of
loop is

for (;;) { ... }
Or:

while (1) { ... }

(Let's not have a lengthy debate about which one is clearer, better,
and/or more idiomatic, ok?)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 9 '07 #9
Keith Thompson said:
"Charlie Gordon" <ne**@chqrlie.orgwrites:
[...]
>TRUE is not really needed, nor welcome, the classic idiom for this kind
of loop is

for (;;) { ... }

Or:

while (1) { ... }

(Let's not have a lengthy debate about which one is clearer, better,
and/or more idiomatic, ok?)
We can make it a very short debate. My vote is "neither".

(And yes, that test is still going.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 9 '07 #10
"Richard Heathfield" <rj*@see.sig.invalida écrit dans le message de news:
bN******************************@bt.com...
Keith Thompson said:
>"Charlie Gordon" <ne**@chqrlie.orgwrites:
[...]
>>TRUE is not really needed, nor welcome, the classic idiom for this kind
of loop is

for (;;) { ... }

Or:

while (1) { ... }

(Let's not have a lengthy debate about which one is clearer, better,
and/or more idiomatic, ok?)
Funny, I did not receive Keith's post. Let's feed the troll:

``for (;;) { ... }'' is unmistakably a testless loop (which you might find
tastless too ;-)

``while (1) { ... }'' can be confused with ``while (l) { ... }'', especially
on Usenet. I would use neither of these.
We can make it a very short debate. My vote is "neither".
Thank you for your constructive criticism, do you mean you use neither of
them, or both, or one but want to keep you preference to yourself ?

--
Chqrlie.
Nov 9 '07 #11
Richard Heathfield wrote:
Charlie Gordon said:

<snip>
>Funny, I did not receive Keith's post. Let's feed the troll:

``for (;;) { ... }'' is unmistakably a testless loop (which you
might find tastless too ;-)

``while (1) { ... }'' can be confused with
``while (l) { ... }'',

That took me a while to spot. Or possibly a for.
Do you mean you have found some difference between the two
statements? I confess I do not see any such. Unless he is using
one and ell, which have the same resolution on my screen.

Aha - I tried it on a hex editor.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Nov 9 '07 #12
"CBFalconer" <cb********@yahoo.coma écrit dans le message de news:
47***************@yahoo.com...
Richard Heathfield wrote:
>Charlie Gordon said:

<snip>
>>Funny, I did not receive Keith's post. Let's feed the troll:

``for (;;) { ... }'' is unmistakably a testless loop (which you
might find tastless too ;-)

``while (1) { ... }'' can be confused with
``while (l) { ... }'',

That took me a while to spot. Or possibly a for.

Do you mean you have found some difference between the two
statements? I confess I do not see any such. Unless he is using
one and ell, which have the same resolution on my screen.

Aha - I tried it on a hex editor.
QED

--
Chqrlie.
Nov 10 '07 #13
Keith Thompson wrote:
>
"Charlie Gordon" <ne**@chqrlie.orgwrites:
[...]
TRUE is not really needed, nor welcome,
the classic idiom for this kind of loop is

for (;;) { ... }

Or:

while (1) { ... }

(Let's not have a lengthy debate about which one is clearer, better,
and/or more idiomatic, ok?)
You've got to be kidding!!!

First of all:
for (;;) { ... } gives No warning on MY compiler.
(for one specific value of "me").
while(1) gives me a warning about a conditional test expression
being constant.

Second of all:
for (;;) { ... } is the K&R example for an endless loop.

Third of all:
It's a special rule in the language for endless loops.
for (;1;); /* compiles */
for (; ;); /* compiles */
while(1); /* compiles */
while( ); /* doesn't compile */

--
pete
Nov 13 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
47
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
20
by: small TUX | last post by:
Hello programmers; I joinded today itself. Can anyone say about the word main, is it a registered word, justify your question also. I would like to point about one thing that we can make variables...
6
by: fatwallet961 | last post by:
is the main function in python is exact compare to Java main method? all execution start in main which may takes arguments? like the follow example script - def main(argv): ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.