Topic: return 1; suggestion
Author: ivr@otenet.gr ("Ioannis Vranos")
Date: Fri, 16 Apr 2004 00:59:15 +0000 (UTC) Raw View
"James Kuyper" <kuyper@wizard.net> wrote in message
news:8b42afac.0404151417.3383656a@posting.google.com...
> ivr@guesswh.at.emails.ru ("Ioannis Vranos") wrote in message
news:<c5m7ap$1f25$1@ulysses.noc.ntua.gr>...
> > Now it may sound a bit stuoid in the beginning. I was talking with
someone
> > who was using return 1; in main() to signal errors because
> >
> > #include <cstdlib>
> >
> >
> > return EXIT_FAILURE;
> >
> >
> > is tiresome to write and also difficult for newbies to understand it.
>
> He finds "return 1;" to be easier to understand than "return
> EXIT_FAILURE;"? The second clearly implies that you're exiting the
> program, and that something failed. I have no idea what a newbie would
> conclude from "return 1", but it's rather unlikely to match what I
> just wrote.
It is easier for a newbie to write return 1; rather than #include <cstdlib>
.. return EXIT_FAILURE; When you were newbie you were returning
EXIT_FAILURE; in main() if you wanted to signal failure?
Ioannis Vranos
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: usenet-nospam@nmhq.net (Niklas Matthies)
Date: Fri, 16 Apr 2004 00:59:27 +0000 (UTC) Raw View
On 2004-04-15 23:09, James Kuyper wrote:
:
> He finds "return 1;" to be easier to understand than "return
> EXIT_FAILURE;"? The second clearly implies that you're exiting the
> program, and that something failed.
Actually, I tend to think that EXIT_FAILURE clearly implies a failure
to exit (whatever is or was being attempted to be exited). ;)
-- Niklas Matthies
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Fri, 16 Apr 2004 15:28:08 +0000 (UTC) Raw View
ivr@otenet.gr ("Ioannis Vranos") wrote in message news:<c5n7mn$qq9$1@ulysses.noc.ntua.gr>...
> "James Kuyper" <kuyper@wizard.net> wrote in message
> news:8b42afac.0404151417.3383656a@posting.google.com...
> > ivr@guesswh.at.emails.ru ("Ioannis Vranos") wrote in message
> news:<c5m7ap$1f25$1@ulysses.noc.ntua.gr>...
> > > Now it may sound a bit stuoid in the beginning. I was talking with
> someone
> > > who was using return 1; in main() to signal errors because
> > >
> > > #include <cstdlib>
> > >
> > >
> > > return EXIT_FAILURE;
> > >
> > >
> > > is tiresome to write and also difficult for newbies to understand it.
> >
> > He finds "return 1;" to be easier to understand than "return
> > EXIT_FAILURE;"? The second clearly implies that you're exiting the
> > program, and that something failed. I have no idea what a newbie would
> > conclude from "return 1", but it's rather unlikely to match what I
> > just wrote.
>
>
> It is easier for a newbie to write return 1; rather than #include <cstdlib>
> .. return EXIT_FAILURE; When you were newbie you were returning
> EXIT_FAILURE; in main() if you wanted to signal failure?
I started using EXIT_FAILURE as soon as I heard of it. That was so
long ago that I can't remember whether it was part of the K&R C that I
first learned, or was an ANSI innovation. If the latter, then it
didn't come into existence until long after I was no longer a newbie.
On the other hand, it was a long time before I realized that "return
EXIT_FAILURE;" was somewhat better than "exit(EXIT_FAILURE);". I don't
remember when I made that transition.
You said it was "difficult for newbies to understand"; now you're
arguing that it's difficult for them to write. Those two different
things. I agree that a newbie might be unfamiliar with the
EXIT_FAILURE macro; a newbie is equally likely to be unfamiliar with
the (implementation-specific) fact that "return 1;" can be used for
that same purpose. Howver, as far as understanding is concerned,
rather than writing, EXIT_FAILURE is wonderfully self-expressive, and
correspondingly easy to understand, making it far superior to '1'.
It's also guaranteed to return an error status, which isn't true of
'1'.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dtmoore@rijnh.nl (Dave Moore)
Date: Fri, 16 Apr 2004 17:40:03 +0000 (UTC) Raw View
snip
>
> It is easier for a newbie to write return 1; rather than #include <cstdlib>
> .. return EXIT_FAILURE; When you were newbie you were returning
> EXIT_FAILURE; in main() if you wanted to signal failure?
>
Hmmm ... I think the logic is backward here ... "easier" doesn't
necessarily mean "better", *especially* for newbies. I agree with
other posters that the named variable is far clearer, even if it
involves a few more keystrokes. When I was a newbie, I understood the
value of name-substitution (e.g. via typedef) for literals, long
before I understood the (arbitrary) convention that <0> means
"success" and <any other int> means failure when returned by a
process. Furthermore, I continue to find it confusing that this is
the opposite of the "natural" int equivalents for booleans, where
false=0 and true=1 (or any other non-zero value). Perhaps this is not
universal, but I find it logical to assume that the pairs (false,
failure), and (true, success) should be correlated, rather than the
reverse.
Finally, why convolute the standard for the sake of newbies? By
definition, they are people who need to learn more about the language
. and making mistakes (like returning 1) is the best way to do this.
In fact, if there were going to be a change made, I would rather see
them get rid of the fixed meaning of {return 0;} for success, and
mandate {return EXIT_SUCCESS;} in its place.
Just my 2 cent ...
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: falk.tannhauser@crf.canon.fr (Falk =?iso-8859-1?Q?Tannh=E4user?=)
Date: Fri, 16 Apr 2004 17:40:14 +0000 (UTC) Raw View
Ioannis Vranos wrote:
>
> "James Kuyper" <kuyper@wizard.net> wrote in message
> > He finds "return 1;" to be easier to understand than "return
> > EXIT_FAILURE;"? The second clearly implies that you're exiting the
> > program, and that something failed. I have no idea what a newbie would
> > conclude from "return 1", but it's rather unlikely to match what I
> > just wrote.
>
> It is easier for a newbie to write return 1; rather than #include <cstdlib>
> .. return EXIT_FAILURE; When you were newbie you were returning
> EXIT_FAILURE; in main() if you wanted to signal failure?
I believe that one thing a newbie should learn is that, in many cases,
it is preferable to have a program that is easy to /read/ than one
that it is easy to /write/.
'EXIT_FAILURE' is clearly more descriptive about the programmer's intention
than '1', even if it requires more keystrokes.
Falk
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Sat, 17 Apr 2004 17:36:22 +0000 (UTC) Raw View
ivr@guesswh.at.emails.ru ("Ioannis Vranos") writes:
> Now it may sound a bit stuoid in the beginning. I was talking with someone
> who was using return 1; in main() to signal errors because
>
> #include <cstdlib>
>
>
> return EXIT_FAILURE;
>
>
> is tiresome to write and also difficult for newbies to understand it.
>
>
> Wouldn't be better this to be added in the upcoming standard as a portable
> way ti signal error? Essentially return 1; to be equivalent to return
> EXIT_FAILURE; as return 0; is equivalent to return EXIT_SUCCESS;
Do you realize that making 'return 1;' equivalent to
'return EXIT_FAILURE;' would make 'return true;' equivalent to
'return EXIT_FAILURE;' as well?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ivr@guesswh.at.emails.ru ("Ioannis Vranos")
Date: Sat, 17 Apr 2004 20:59:21 +0000 (UTC) Raw View
"llewelly" <llewelly.at@xmission.dot.com> wrote in message
news:86n05bcmbb.fsf@Zorthluthik.local.bar...
> ivr@guesswh.at.emails.ru ("Ioannis Vranos") writes:
>
> Do you realize that making 'return 1;' equivalent to
> 'return EXIT_FAILURE;' would make 'return true;' equivalent to
> 'return EXIT_FAILURE;' as well?
While now returning true in main() is undefined behaviour.
Ioannis Vranos
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Sun, 18 Apr 2004 21:09:28 +0000 (UTC) Raw View
ivr@guesswh.at.emails.ru ("Ioannis Vranos") writes:
> "llewelly" <llewelly.at@xmission.dot.com> wrote in message
> news:86n05bcmbb.fsf@Zorthluthik.local.bar...
>> ivr@guesswh.at.emails.ru ("Ioannis Vranos") writes:
>>
>> Do you realize that making 'return 1;' equivalent to
>> 'return EXIT_FAILURE;' would make 'return true;' equivalent to
>> 'return EXIT_FAILURE;' as well?
>
>
> While now returning true in main() is undefined behaviour.
[snip]
I would like to see it become a required diagnostic. I'm chary of how
much code that would break, however. And it doesn't seem terribly
important.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ark@acm.org ("Andrew Koenig")
Date: Mon, 19 Apr 2004 16:08:04 +0000 (UTC) Raw View
""Ioannis Vranos"" <ivr@guesswh.at.emails.ru> wrote in message
news:c5s2i1$7ub$1@ulysses.noc.ntua.gr...
> > Do you realize that making 'return 1;' equivalent to
> > 'return EXIT_FAILURE;' would make 'return true;' equivalent to
> > 'return EXIT_FAILURE;' as well?
> While now returning true in main() is undefined behaviour.
Really? Why do you think so?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Michiel.Salters@logicacmg.com (Michiel Salters)
Date: Mon, 19 Apr 2004 17:35:10 +0000 (UTC) Raw View
ivr@guesswh.at.emails.ru ("Ioannis Vranos") wrote in message news:<c5s2i1$7ub$1@ulysses.noc.ntua.gr>...
> "llewelly" <llewelly.at@xmission.dot.com> wrote in message
> news:86n05bcmbb.fsf@Zorthluthik.local.bar...
> > ivr@guesswh.at.emails.ru ("Ioannis Vranos") writes:
> >
> > Do you realize that making 'return 1;' equivalent to
> > 'return EXIT_FAILURE;' would make 'return true;' equivalent to
> > 'return EXIT_FAILURE;' as well?
>
>
> While now returning true in main() is undefined behaviour.
>
No. true is converted to 1, which means main() returns 1. This is
equivalent to exit(1). The meaning of exit(1) is implementation-
defined per 18.3/8, and not undefined.
Regards,
Michiel Salters
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: llewelly.at@xmission.dot.com (llewelly)
Date: Mon, 19 Apr 2004 17:37:17 +0000 (UTC) Raw View
ark@acm.org ("Andrew Koenig") writes:
> ""Ioannis Vranos"" <ivr@guesswh.at.emails.ru> wrote in message
> news:c5s2i1$7ub$1@ulysses.noc.ntua.gr...
>
>> > Do you realize that making 'return 1;' equivalent to
>> > 'return EXIT_FAILURE;' would make 'return true;' equivalent to
>> > 'return EXIT_FAILURE;' as well?
>
>> While now returning true in main() is undefined behaviour.
>
> Really? Why do you think so?
hm, the 3rd bullet of 18.3/8 says it is implementation-defined
behaviour. I'd forgotten that.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ivr@guesswh.at.emails.ru ("Ioannis Vranos")
Date: Mon, 19 Apr 2004 20:17:48 +0000 (UTC) Raw View
""Andrew Koenig"" <ark@acm.org> wrote in message
news:yuQgc.2264$um3.61459@bgtnsc04-news.ops.worldnet.att.net...
>
> > While now returning true in main() is undefined behaviour.
>
> Really? Why do you think so?
Ok let me rephrase: "While now returning true in main() is implementation
defined behaviour."
Which means we can not expect a specific behaviour from all implementations.
Which for me is the same about the same for this context.
Ioannis Vranos
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ivr@guesswh.at.emails.ru ("Ioannis Vranos")
Date: Mon, 19 Apr 2004 21:45:59 +0000 (UTC) Raw View
""Ioannis Vranos"" <ivr@guesswh.at.emails.ru> wrote in message
news:c61c0s$2kko$1@ulysses.noc.ntua.gr...
>
> Which for me is the same about the same for this context.
.. Which for me is about the same for this context.
Ioannis Vranos
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ivr@guesswh.at.emails.ru ("Ioannis Vranos")
Date: Thu, 15 Apr 2004 17:10:52 +0000 (UTC) Raw View
Now it may sound a bit stuoid in the beginning. I was talking with someone
who was using return 1; in main() to signal errors because
#include <cstdlib>
return EXIT_FAILURE;
is tiresome to write and also difficult for newbies to understand it.
Wouldn't be better this to be added in the upcoming standard as a portable
way ti signal error? Essentially return 1; to be equivalent to return
EXIT_FAILURE; as return 0; is equivalent to return EXIT_SUCCESS;
Ioannis Vranos
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Thu, 15 Apr 2004 19:48:46 +0000 (UTC) Raw View
"Ioannis Vranos" wrote:
> Now it may sound a bit stuoid in the beginning. I was talking with someone
> who was using return 1; in main() to signal errors because
>
> #include <cstdlib>
>
>
> return EXIT_FAILURE;
>
>
> is tiresome to write
Oh, the agony. You only have to write it once per program.
> and also difficult for newbies to understand it.
The #include may be obscure, but that's something that has to be
learnt anyway. The named constant is surely helpful to "newbies" and
others. It's not exactly obvious that 0 means success and 1 means
failure; in fact it's the inverse of what one might expect.
> Wouldn't be better this to be added in the upcoming standard as a portable
> way ti signal error? Essentially return 1; to be equivalent to return
> EXIT_FAILURE; as return 0; is equivalent to return EXIT_SUCCESS;
That might break a platform-specific C++ program that currently
returns 1 on a platform where this doesn't indicate failure. For
example, on VMS a return code of 1 indicates success. (I suspect that
C++ implementations on VMS change a return code of 0 to 1 and vice
versa, but this certainly isn't required.)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Thu, 15 Apr 2004 23:09:23 +0000 (UTC) Raw View
ivr@guesswh.at.emails.ru ("Ioannis Vranos") wrote in message news:<c5m7ap$1f25$1@ulysses.noc.ntua.gr>...
> Now it may sound a bit stuoid in the beginning. I was talking with someone
> who was using return 1; in main() to signal errors because
>
> #include <cstdlib>
>
>
> return EXIT_FAILURE;
>
>
> is tiresome to write and also difficult for newbies to understand it.
He finds "return 1;" to be easier to understand than "return
EXIT_FAILURE;"? The second clearly implies that you're exiting the
program, and that something failed. I have no idea what a newbie would
conclude from "return 1", but it's rather unlikely to match what I
just wrote.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: loic.actarus.joly@wanadoo.fr (=?ISO-8859-1?Q?Lo=EFc_Joly?=)
Date: Thu, 15 Apr 2004 23:25:51 +0000 (UTC) Raw View
Ioannis Vranos wrote:
> Now it may sound a bit stuoid in the beginning. I was talking with some=
one
> who was using return 1; in main() to signal errors because
>=20
> #include <cstdlib>
>=20
>=20
> return EXIT_FAILURE;
>=20
>=20
> is tiresome to write and also difficult for newbies to understand it.
>=20
>=20
> Wouldn't be better this to be added in the upcoming standard as a porta=
ble
> way ti signal error? Essentially return 1; to be equivalent to return
> EXIT_FAILURE; as return 0; is equivalent to return EXIT_SUCCESS;
Well, I do agree the there is an inconsistency between the success and=20
the failure case, and that this inconsistency can make learning C++ a=20
(very) little bit more complex.
My proposal would be just the opposite of yours : Just don't mandate any=20
value for EXIT_SUCCESS.
--=20
Lo=EFc
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]