Topic: Examples.
Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1998/09/09 Raw View
James Kuyper <kuyper@wizard.net> writes:
> IMHO, that is one of the key characteristics that distinguishes
> right and wrong C++ code.
It seems that the committee was aware of the various associations that
native speakers have with 'right' and 'wrong', and worded it as
'well-formed' and 'ill-formed' instead :-)
Regards,
Martin
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Al Stevens" <alstevens@midifitz.com>
Date: 1998/09/09 Raw View
>The special rule about returning zero implicitly simply
>recognizes existing practice in both C and C++. Many C and C++
>compilers have historically never required a return statement,
>and treat a missing return as if "return 0;" were present.
Many legacy C compilers would simply return from main whatever happened to
be in the register that the compiler used to return integer values
(typically AX). K&R compilers would do that, too, for other functions that
neglected to return something.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/10 Raw View
> >In article <slrn6v64ta.98p.sbnaran@localhost.localdomain>,
> > sbnaran@KILL.uiuc.edu wrote:
> >> I was wondering, why does standard C++ not accept the following
> >> signatures, which g++ allows if you don't use the --pedantic
> >> switch?
> >> int main(int argc, char const *const argv[]);
> In article <6t4n5l$cda$1@nnrp1.dejanews.com>,
> I, <AllanW@my-dejanews.com> wrote:
> >Because you can't implicitly convert a char const*const*
> >to a char**. There are good reasons for this.
> >
> >OTOH, the correct signature
> > int main(int argc, char*argv[])
> >does imply that you can safely modify the argv data. This is
> >IMHO a mistake, but it wasn't made in the C++ committee -- it
> >was a mistake in the original C (or whichever C was the first
> >one to specify function prototypes). Since C does it, C++ must
> >continue to do it.
In article <6t5qh5$1os$1@news.lth.se>,
Email_To::.Hans.Olsson@dna.lth.se (Hans Olsson) wrote:
> This is not an argument against const-qualifying argv
[goes on to point out that main can be overloaded, even in C]
You're right, it isn't. I wish that the standard had listed the
const-qualified main() as a required alternative. If it did, some
of us would use it for all new C++ programs...
What I meant, above, is that since C supports the non-const
signature, it will be with us in C++ for a long time, even if
it's deprecated.
> and at least CD2 (and thus probably the standard) allows a compiler to
> also accept
>
> int main(int argc,char const *const argv[])
>
> Unfortunately the compiler is not required to accept it.
Which means we can't use it in portable programs.
[Quoting the standard]
> [Note: it is recommended that any further (optional) parameters be added
> after argv. ]
This is also a legacy of C. Many systems accept a third pointer of the
form
const *envp[]
which specifies a list of "environmental variables" (with OS-defined
meaning). AFAIK, no version of C or C++ standards has ever either
required or blocked a compiler from accepting this.
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Matt Austern <austern@sgi.com>
Date: 1998/09/10 Raw View
alanstokes@my-dejanews.com writes:
> Similarly falling off the end of main is a bad thing to do, IMHO, and I would
> expect a warning. (If you don't think it's bad, fair enough - disable the
> warning.)
No, falling off the end of main is correct. According to the C++
standard, it is equivalent to "return 0".
You might choose to avoid it for stylistic reasons, of course, just as
you might have stylistic convensions for your choice of variable
names.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: alanstokes@my-dejanews.com
Date: 1998/09/10 Raw View
In article <fxtww7dhvz7.fsf@isolde.engr.sgi.com>,
Matt Austern <austern@sgi.com> wrote:
> alanstokes@my-dejanews.com writes:
>
> > Similarly falling off the end of main is a bad thing to do, IMHO, and I would
> > expect a warning. (If you don't think it's bad, fair enough - disable the
> > warning.)
>
> No, falling off the end of main is correct. According to the C++
> standard, it is equivalent to "return 0".
Of course it's correct; I never said it wasn't - I said it was in my opinion a
bad thing to do. If it was incorrect then there should be an error message (a
required diagnostic), not a warning. This thread has been all about whether
issuing a _warning_ is sensible/correct/right.
> You might choose to avoid it for stylistic reasons, of course, just as
> you might have stylistic convensions for your choice of variable
> names.
Warnings are all about correct but stylistically dubious code. That's why a
compiler should produce a warning in this case.
Of course you may think this is stylistically a perfectly OK thing to do, and
I don't have any problem with that; that's why warnings should always be
capable of being suppressed.
--
- Alan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Matt Austern <austern@sgi.com>
Date: 1998/09/12 Raw View
alanstokes@my-dejanews.com writes:
> > You might choose to avoid it for stylistic reasons, of course, just as
> > you might have stylistic convensions for your choice of variable
> > names.
>
> Warnings are all about correct but stylistically dubious code. That's why a
> compiler should produce a warning in this case.
Warnings, of course, aren't addressed by the standard: a compiler can
warn about anything the compiler vendor chooses.
Personally, though, I wouldn't like a compiler that issued a warning
about everything that anyone ever thought was bad style. It would
issue too many warnings, it would be hard to tell the signal from the
noise, and I'd have to litter my code with unportable pragmas to get a
clean compile.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/09 Raw View
In article <6srglb$rbs$1@rocky.jgk.org>,
Joe Keane <jgk@jgk.org> wrote:
> In article <6sfib6$v35$1@nnrp1.dejanews.com>
> AllanW@my-dejanews.com writes:
> >Which means that if your compiler, like most compilers, issues a
> >warning statement, then the warning is incorrect.
>
> It's not,
Yes, it is.
> Over time, i've dealt with too many programs that return 10 on success.
> I now firmly believe that someone who forgets the "return 0;" in `main'
> is stupid or a lazy ass and probably should get smacked around a bit.
That shouldn't happen (anymore) by accident. If you exit main()
without a return statement, the result is supposed to be *identical*
to return 0. Note that this does not apply to functions other than
main; i.e.
int sub()
{
// comment
}
has undefined results.
> It's true that the C++ standard condones this, as well as multiple
> signatures for `main', and probably other dumb things. That doesn't
> mean it's right, but it is the standard.
What's the difference between what's right and what the standard
says is right?
> It may help to consider that
> perhaps other similar languages do not behave this way.
There may be many things that are valid in one language and not in
another. For things that are valid in both languages, the semantics
may be one thing in one language and another thing in another
language. That's what standards are for -- to define what "right"
means!
> By the way, i couldn't find this, what is the proper declaration for a
> function such that it will return 0 in case the end is reached?
For the special case of main(), it is
int main(int argc, char *argv[]) {
// Insert statements here
}
For any other function, there is no such definition. But this is
similar to what you requested:
int sub() {
// Insert statements here
// Language requires all return statements to have a value
// Consider this comment to be "the end" of function sub()
// This statement is executed if and only if
// the code above did not already return a value.
return 0;
}
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/09 Raw View
In article <slrn6v64ta.98p.sbnaran@localhost.localdomain>,
sbnaran@KILL.uiuc.edu wrote:
> I was wondering, why does standard C++ not accept the following
> signatures, which g++ allows if you don't use the --pedantic
> switch?
> int main(int argc, char const *const argv[]);
Because you can't implicitly convert a char const*const*
to a char**. There are good reasons for this.
OTOH, the correct signature
int main(int argc, char*argv[])
does imply that you can safely modify the argv data. This is
IMHO a mistake, but it wasn't made in the C++ committee -- it
was a mistake in the original C (or whichever C was the first
one to specify function prototypes). Since C does it, C++ must
continue to do it.
> In any case, why did the standards committee go out of their way to
> make all these special rules for main(...)? It's really not a big
> deal that we have to put "return 0" in body of main(...).
Because there's a great deal of code that doesn't use a return
statement in main(), and the committee had to choose between
making it invalid, or defining some reasonable result.
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/09/09 Raw View
sbnaran@localhost.localdomain (Siemel Naran) writes:
>In any case, why did the standards committee go out of their way to
>make all these special rules for main(...)? It's really not a big
>deal that we have to put "return 0" in body of main(...).
The special rules about the signature are the same as in C.
The special rules about not being able to take the address of or
call main are there to allow implementations to do whatever is
necessary for initialization of namespace-scope static objects.
(C doesn't have that problem, and can allow main to be called
recursively. Calling main in C++ has always been disallowed.)
The special rule about returning zero implicitly simply
recognizes existing practice in both C and C++. Many C and C++
compilers have historically never required a return statement,
and treat a missing return as if "return 0;" were present.
--
Steve Clamage, stephen.clamage@sun.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Email_To::.Hans.Olsson@dna.lth.se (Hans Olsson)
Date: 1998/09/09 Raw View
In article <6t4n5l$cda$1@nnrp1.dejanews.com>, <AllanW@my-dejanews.com> wrote:
>
>In article <slrn6v64ta.98p.sbnaran@localhost.localdomain>,
> sbnaran@KILL.uiuc.edu wrote:
>> I was wondering, why does standard C++ not accept the following
>> signatures, which g++ allows if you don't use the --pedantic
>> switch?
>> int main(int argc, char const *const argv[]);
>
>Because you can't implicitly convert a char const*const*
>to a char**. There are good reasons for this.
>
>OTOH, the correct signature
> int main(int argc, char*argv[])
>does imply that you can safely modify the argv data. This is
>IMHO a mistake, but it wasn't made in the C++ committee -- it
>was a mistake in the original C (or whichever C was the first
>one to specify function prototypes). Since C does it, C++ must
>continue to do it.
This is not an argument against const-qualifying argv
because C++ standard already allows both
int main()
and
int main(int argc,char*argv[])
and at least CD2 (and thus probably the standard) allows a compiler to
also accept
int main(int argc,char const *const argv[])
Unfortunately the compiler is not required to accept it.
The wording is:
It [=main] shall have a return type of type int, but otherwise its type
is implementation-defined. All implementations shall allow both of the
following definitions of main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
...
[Note: it is recommended that any further (optional) parameters be added
after argv. ]
--
// Home page http://www.dna.lth.se/home/Hans_Olsson/
// Email To..Hans.Olsson@dna.lth.se [Please no junk e-mail]
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: alanstokes@my-dejanews.com
Date: 1998/09/09 Raw View
In article <6t4l0q$9at$1@nnrp1.dejanews.com>,
AllanW@my-dejanews.com wrote:
>
> In article <6srglb$rbs$1@rocky.jgk.org>,
> Joe Keane <jgk@jgk.org> wrote:
> > It's true that the C++ standard condones this, as well as multiple
> > signatures for `main', and probably other dumb things. That doesn't
> > mean it's right, but it is the standard.
>
> What's the difference between what's right and what the standard
> says is right?
The standard doesn't say anything is right or wrong, it says whether it means
something or not in C++.
A statement such as "if (a = 0);" has a perfectly well defined meaning
according to the standard. However it is not at all right; there are two very
bad things in it that I would expect any decent quality compiler to warn me
about (did you really mean assignment not equality? did you really mean that
null statement?).
Similarly falling off the end of main is a bad thing to do, IMHO, and I would
expect a warning. (If you don't think it's bad, fair enough - disable the
warning.)
--
- Alan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/09/09 Raw View
alanstokes@my-dejanews.com wrote:
>
> In article <6t4l0q$9at$1@nnrp1.dejanews.com>,
> AllanW@my-dejanews.com wrote:
> >
> > In article <6srglb$rbs$1@rocky.jgk.org>,
> > Joe Keane <jgk@jgk.org> wrote:
>
> > > It's true that the C++ standard condones this, as well as multiple
> > > signatures for `main', and probably other dumb things. That doesn't
> > > mean it's right, but it is the standard.
> >
> > What's the difference between what's right and what the standard
> > says is right?
>
> The standard doesn't say anything is right or wrong, it says whether it means
> something or not in C++.
More accurately, it says what a conforming implementation should do as a
result of translating source code. It particular, it says what code a
conforming implementation is allowed to refuse to translate. IMHO, that
is one of the key characteristics that distinguishes right and wrong C++
code.
> A statement such as "if (a = 0);" has a perfectly well defined meaning
> according to the standard. However it is not at all right; there are two very
> bad things in it that I would expect any decent quality compiler to warn me
> about (did you really mean assignment not equality? did you really mean that
> null statement?).
Keep in mind that the answer to both questions could be "Yes". The 0
value and the null statement could both be the legitimate results of
special cases in automatic code generation, or in the expansion of a
macro.
> Similarly falling off the end of main is a bad thing to do, IMHO, and I would
> expect a warning. (If you don't think it's bad, fair enough - disable the
> warning.)
There are an awful lot of programs out there where the return value from
main() is absolutely irrelevant.
The standard says nothing about warnings. An implementation is free to
provide any warnings it wants. I'd appreciate such a warning.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/09/07 Raw View
Joe Keane wrote:
...
> By the way, i couldn't find this, what is the proper declaration for a
> function such that it will return 0 in case the end is reached?
The only 'function' for which that occurs is identified as such by its
name, not by its declaration. Was there a missing smiley on that
question?
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1998/09/07 Raw View
On 06 Sep 98 07:09:03 GMT, Joe Keane <jgk@jgk.org> wrote:
>Over time, i've dealt with too many programs that return 10 on success.
>I now firmly believe that someone who forgets the "return 0;" in `main'
>is stupid or a lazy ass and probably should get smacked around a bit.
For small programs like test drivers and examples of how C++ works,
a missing return on main(...) is ok as the program will always
return 0. For more useful programs that may return 0 or 1 or
whatever, an explicit "return 0" when appropriate is a good idea.
>It's true that the C++ standard condones this, as well as multiple
>signatures for `main', and probably other dumb things. That doesn't
>mean it's right, but it is the standard. It may help to consider that
>perhaps other similar languages do not behave this way.
I was wondering, why does standard C++ not accept the following
signatures, which g++ allows if you don't use the --pedantic
switch?
int main(int argc, char const *const argv[]);
>By the way, i couldn't find this, what is the proper declaration for a
>function such that it will return 0 in case the end is reached?
In any case, why did the standards committee go out of their way to
make all these special rules for main(...)? It's really not a big
deal that we have to put "return 0" in body of main(...).
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "J. Harmse" <harmse@galileo.tracor.com>
Date: 1998/08/31 Raw View
Should example code in the standard be correct? I think that even code
intended to illustrate errors should contain only the errors to be
illustrated,
and no other errors or bad coding practice.
For example, the following is in Chapter 4.4 (Footnote 3) of the December
1996 draft:
main() {
const char c = 'c';
char* pc;
const char** pcc = &pc; //1: not allowed
*pcc = &c;
*pc = 'C'; //2: modifies a const object
}
Implicit integer type should be removed from C, and should never have been
part of C++. That it's still legal is no excuse for using it. Failure to
return a value
is a run-time error, and any decent compiler will issue a warning. The
example
should be:
int main()
{ const char c = 'c';
char* pc;
const char** pcc = &pc; //1: not allowed
*pcc = &c;
*pc = 'C'; //2: modifies a const object
return 0;
}
(The improper conversion is the point of the example, and should be kept.)
J. Harmse.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/08/31 Raw View
In article <01bdd503$3dd6d6f0$7465bd83@harmse>, J. Harmse
<harmse@galileo.tracor.com> writes
> That it's still legal is no excuse for using it. Failure to
>return a value
>is a run-time error, and any decent compiler will issue a warning. The
>example
>should be:
Of course exemplar code should be 'correct' but did you volunteer to do
a complete code review of CD2? (Those of us actually doing the work had
some rather more important issues to resolve.) Of course that requires
that you actually know what the standard says:) main() has been a
special case as regards return for at least five years. Falling out of
main without returning is deemed to be equivalent to return 0; Any
compiler issueing a warning is providing an unecessary diagnostic.
--
Francis Glassborow
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ark@research.att.com (Andrew Koenig)
Date: 1998/09/01 Raw View
In article <01bdd503$3dd6d6f0$7465bd83@harmse>,
J. Harmse <harmse@galileo.tracor.com> wrote:
> Implicit integer type should be removed from C, and should never have been
> part of C++. That it's still legal is no excuse for using it. Failure to
> return a value
> is a run-time error, and any decent compiler will issue a warning. The
> example
> should be:
> int main()
> { const char c = 'c';
> char* pc;
> const char** pcc = &pc; //1: not allowed
> *pcc = &c;
> *pc = 'C'; //2: modifies a const object
> return 0;
> }
The standard does indeed say `int main.'
It doesn't have a return statement, because `main' has a special dispensation
to omit it.
--
Andrew Koenig
ark@research.att.com
http://www.research.att.com/info/ark
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: brownsta@concentric.net (Stan Brown)
Date: 1998/09/05 Raw View
petebecker@acm.org (Pete Becker) wrote:
>Jerry Coffin wrote:
>> > After all, the constitution of the United States is public.
>>
>> There are lots of places you can go to see copies of the U.S.
>> Constituion. If you want a copy of your own, you have to pay somebody
>> for a printed copy. Since it fits on one page and had a fairly wide
>> audience, copies are relatively inexpensive.
>
>Andy Koenig experimented a bit at one of the standards meetings with
>techniques for putting the C++ standard on one or two pages. The result
>was interesting, but unacceptable: it was too hard to read. Putting the
>U.S. Constitution on a single page would run into a similar problem. My
>copy is 7 pages, plus 4 for the amendments. <g>
Nor do you have to pay for a printed copy. there are many, many Web sites
where you can download it and print it for nothing more than the cost of
connect time and your own paper.
It is also legal to photocopy the Constitution from any book or other
medium. It is not only public, but public domain (even if reprinted in a
copyrighted work).
That doesn't (necessarily) mean the C++ Standard should be available
gratis; it just means the analogy is not a good one.
--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.concentric.net/%7eBrownsta/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/09/05 Raw View
In article <35F00E95.9F063FC@acm.org>, petebecker@acm.org says...
[ ... ]
> Andy Koenig experimented a bit at one of the standards meetings with
> techniques for putting the C++ standard on one or two pages. The result
> was interesting, but unacceptable: it was too hard to read.
Hmm...depends on how good of a microscope you use, I s'pose. Let's
see: with line thicknesses of .18 microns, each letter would be around
.8 microns wide and about twice that tall. At around 600 pages, and
about 4000 characters per page, we should be able to fit the entire
thing on a 2000x2000 micron slice of silicon. Of course, this would
tend to drive the price up even higher...
> Putting the U.S. Constitution on a single page would run into a
> similar problem. My copy is 7 pages, plus 4 for the amendments. <g>
Well, okay eleven pages (I was thinking of the Declaration of
Independence...) but it's still a whole lot less smaller than the C++
standard.
--
Later,
Jerry.
The Universe is a figment of its own imagination.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Joe Keane <jgk@jgk.org>
Date: 1998/09/06 Raw View
In article <6sfib6$v35$1@nnrp1.dejanews.com>
AllanW@my-dejanews.com writes:
>Which means that if your compiler, like most compilers, issues a
>warning statement, then the warning is incorrect.
It's not,
Over time, i've dealt with too many programs that return 10 on success.
I now firmly believe that someone who forgets the "return 0;" in `main'
is stupid or a lazy ass and probably should get smacked around a bit.
It's true that the C++ standard condones this, as well as multiple
signatures for `main', and probably other dumb things. That doesn't
mean it's right, but it is the standard. It may help to consider that
perhaps other similar languages do not behave this way.
By the way, i couldn't find this, what is the proper declaration for a
function such that it will return 0 in case the end is reached?
--
Joe Keane, amateur mathematician
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/09/02 Raw View
On 31 Aug 1998 20:28:58 GMT, J. Harmse <harmse@galileo.tracor.com> wrote:
>int main()
>{ const char c = 'c';
> char* pc;
> const char** pcc = &pc; //1: not allowed
> *pcc = &c;
> *pc = 'C'; //2: modifies a const object
> return 0;
>}
The "return 0" is not necessary because main(...) doesn't need to
have a return -- "return 0" is implied. Regarding the function
prototype, you're right: it should be "int main()" and not
"main()".
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/09/02 Raw View
"J. Harmse" <harmse@galileo.tracor.com> writes:
>Should example code in the standard be correct?
Yes, it should.
> I think that even code
>intended to illustrate errors should contain only the errors to be
>illustrated, and no other errors or bad coding practice.
Ideally, yes.
>For example, the following is in Chapter 4.4 (Footnote 3) of the December
>1996 draft:
>main() {
> const char c = 'c';
> char* pc;
> const char** pcc = &pc; //1: not allowed
> *pcc = &c;
> *pc = 'C'; //2: modifies a const object
>}
>Implicit integer type should be removed from C, and should never have been
>part of C++. That it's still legal is no excuse for using it.
Implicit int is not part of C++, and that example was incorrect
in that regard. But, as explained in the FAQ for this newsgroup,
the Dec 1996 draft is out of date. Numerous errors in that draft
were corrected. In particular, that example in the final draft now
contains a return type of int for main.
> Failure to return a value
>is a run-time error, and any decent compiler will issue a warning.
No, function main is special in many regards. In particular,
no return statement is required, and if none is present, the
function returns a value of 0. That provision was present even
in the first public-comment version of April 1995.
Reference: Section 3.6.1 "Main function", any version of the draft.
--
Steve Clamage, stephen.clamage@sun.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1998/09/02 Raw View
Francis Glassborow <francis@robinton.demon.co.uk> writes:
>Of course exemplar code should be 'correct' but did you volunteer to do
>a complete code review of CD2? (Those of us actually doing the work had
>some rather more important issues to resolve.)
I don't think that's a fair criticism. Anyone should be allowed
(nay, encouraged) to report a potential error in the standard
without volunteering to proofread all 700+ pages.
But errors should be reported against the final standard, not against
intermediate drafts.
--
Steve Clamage, stephen.clamage@sun.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/02 Raw View
In article <01bdd503$3dd6d6f0$7465bd83@harmse>,
"J. Harmse" <harmse@galileo.tracor.com> wrote:
>
> Should example code in the standard be correct? I think that even code
> intended to illustrate errors should contain only the errors to be
> illustrated, and no other errors or bad coding practice.
I would agree with this.
> For example, the following is in Chapter 4.4 (Footnote 3) of the December
> 1996 draft:
>
> main() {
> const char c = 'c';
> char* pc;
> const char** pcc = &pc; //1: not allowed
> *pcc = &c;
> *pc = 'C'; //2: modifies a const object
> }
>
> Implicit integer type should be removed from C, and should never have
> been part of C++. That it's still legal is no excuse for using it.
Perhaps that is slightly misleading in this example. Even if it's
legal, it's not advised, but it's also not the topic under
discussion. This diverts attention away from the error that *is*
under discussion.
> Failure to return a value is a run-time error,
> and any decent compiler will issue a warning.
Well, no. Function main() is a specific exception; if main completes
the last statement without executing return, the effect is the same as
if the function had executed
return 0;
Which means that if your compiler, like most compilers, issues a
warning statement, then the warning is incorrect. (This does not
make the compiler non-compliant so long as the code works correctly.
Compilers are allowed to issue extra warning messages. Nor does it
make the compiler non-"decent" so long as the vast majority of
compilers have the same problem, which they do.)
> The example should be:
>
> int main()
> { const char c = 'c';
> char* pc;
> const char** pcc = &pc; //1: not allowed
> *pcc = &c;
> *pc = 'C'; //2: modifies a const object
> return 0;
> }
>
> (The improper conversion is the point of the example, and should be kept.)
That's much better than the original. But since main() has special
properties, and since the returned value doesn't demonstrate either
errors or correct code for the topic under discussion, perhaps some
void function would be even more appropriate.
void bad_function() {
// ... insert example statements here ...
}
As you say, the important point is that examples of errors should
demonstrate only the type of error being discussed, and that all
errors should be so labelled.
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/02 Raw View
In article <gio9EhAOxx61EwLq@robinton.demon.co.uk>,
Francis Glassborow <francis@robinton.demon.co.uk> wrote:
>
> In article <01bdd503$3dd6d6f0$7465bd83@harmse>, J. Harmse
> <harmse@galileo.tracor.com> writes
> > That it's still legal is no excuse for using it. Failure to
> >return a value
> >is a run-time error, and any decent compiler will issue a warning. The
> >example
> >should be:
>
> Of course exemplar code should be 'correct' but did you volunteer to do
> a complete code review of CD2? (Those of us actually doing the work had
> some rather more important issues to resolve.)
Getting defensive won't help the problem go away. Please note that
Mr. Harmse didn't attack anyone, he simply pointed out an omission in
the standard. This *is* the correct place to do that.
Some of us who now have a chance to be regular contributors to this
newsgroup haven't always had that opportunity. I appreciate all of
the hard work that has gone on in the past, and I hope to be helpful
in the future, even if I'm not able to join the standards committees
directly. I assume you don't insist that those who haven't helped in
the past may not do so in the present.
> Of course that requires
> that you actually know what the standard says:)
Despite the smiley, this seems a bit harsh. Are you familiar with
every word in the standard? If so, then please accept my
congratulations; but why didn't you catch the item Mr. Harmse
just pointed out?
> main() has been a special case as regards return for at least
> five years. Falling out of main without returning is deemed to be
> equivalent to return 0; Any compiler issueing a warning is
> providing an unecessary diagnostic.
Quite true. But that wasn't the point being made in this example,
and it could possibly divert the reader's attention away from what
it purports to discuss.
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/09/02 Raw View
In article <6si3vu$ret$1@nnrp1.dejanews.com>, AllanW@my-dejanews.com
writes
>> main() has been a special case as regards return for at least
>> five years. Falling out of main without returning is deemed to be
>> equivalent to return 0; Any compiler issueing a warning is
>> providing an unecessary diagnostic.
>
>Quite true. But that wasn't the point being made in this example,
>and it could possibly divert the reader's attention away from what
>it purports to discuss.
Then why did he write:
That it's still legal is no excuse for using it. Failure to
return a value
is a run-time error, and any decent compiler will issue a warning. The
example
should be:
I do not expect anyone to be familiar with the whole 700 pages (there
aren't many that are familiar with the 200 pages of C:) and I am more
than happy to see people point out errors, confusions and ambiguities
but pointing these out should be exactly that. I was (probably through
tiredness) irritated by the above quote (a certain popular compiler is
particularly good at telling me that it has willfully decided to change
my int main() to void main() or declines to translate my correctly
written code:)
--
Francis Glassborow
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/09/02 Raw View
Francis Glassborow wrote:
> In article <6si3vu$ret$1@nnrp1.dejanews.com>, AllanW@my-dejanews.com
> writes
> >> main() has been a special case as regards return for at least
> >> five years. Falling out of main without returning is deemed to be
> >> equivalent to return 0; Any compiler issueing a warning is
> >> providing an unecessary diagnostic.
...
> That it's still legal is no excuse for using it. Failure to
> return a value
> is a run-time error, and any decent compiler will issue a warning. The
> example should be:
It's not a run-time error in standard C++. However, you are right, most
compilers are somewhat out-of-date on this issue, and will report an
inappropriate warning on the matter.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/09/02 Raw View
In article <gio9EhAOxx61EwLq@robinton.demon.co.uk>,
Francis Glassborow <francis@robinton.demon.co.uk> wrote:
> >> main() has been a special case as regards return for at least
> >> five years. Falling out of main without returning is deemed to be
> >> equivalent to return 0; Any compiler issueing a warning is
> >> providing an unecessary diagnostic.
In article <6si3vu$ret$1@nnrp1.dejanews.com>, AllanW@my-dejanews.com
writes
> >Quite true. But that wasn't the point being made in this example,
> >and it could possibly divert the reader's attention away from what
> >it purports to discuss.
In article <sxVgkhAz8R71Ewip@robinton.demon.co.uk>,
Francis Glassborow <francis@robinton.demon.co.uk> wrote:
> Then why did he write:
>
[Quoting "J. Harmse" in article <01bdd503$3dd6d6f0$7465bd83@harmse>]
> > That it's still legal is no excuse for using it. Failure to
> > return a value
> > is a run-time error, and any decent compiler will issue a warning. The
> > example
> > should be:
He wrote it because the example was unfocused. Did you read something
else into Mr. Harmse's comments? (For the sake of being non-PC, I'll
assume that "J. Harmse" is male.)
The example from the spec was supposed to demonstrate using const with
pointer types. But in the version in CD2, which Mr. Harmse was
evidently reading, it also confused the issue by:
(1) Using a less-than-well-known feature about main. Many people,
apparently including Mr. Harmse, don't know or fully understand
the special rule that makes return statements optional in main;
indeed, all of the compilers that I use get this wrong (issuing
a warning message for perfectly valid code). It's important to
document this, of course, but this isn't the right place -- it's
not relevant to the topic being discussed (which is, remember:
using const with pointer types).
and, also in that draft (I understand it was repaired in the final
draft, but we don't all have access to that):
(2) An error never pointed out in comments or narration,
specifically declaring main without any return type.
Even with narration this would have been a bad idea,
because it is not relevant to the topic being discussed
(which is, remember: using const with pointer types).
In particular, Mr. Harmse was distracted by both of these issues.
He apparently didn't know about rule (1), but even if he had known,
why should it be shown in this example? He certainly did understand
rule (2), and his revised example didn't demonstrate this problem.
In any case, I believe he made his point that the example should
be changed.
> I do not expect anyone to be familiar with the whole 700 pages (there
> aren't many that are familiar with the 200 pages of C:) and I am more
> than happy to see people point out errors, confusions and ambiguities
> but pointing these out should be exactly that.
But that's exactly what Mr. Harmse did, and you seemed quite UN-happy.
There wasn't anything personal in what Mr. Harmse said, but your
response was:
> Of course exemplar code should be 'correct' but did you volunteer to do
> a complete code review of CD2? (Those of us actually doing the work had
> some rather more important issues to resolve.)
and
> Of course that requires
> that you actually know what the standard says:)
This seems quite personal to me, which is against the newsgroup
charter. Moderator?
> I was (probably through
> tiredness) irritated by the above quote (a certain popular compiler is
> particularly good at telling me that it has willfully decided to change
> my int main() to void main() or declines to translate my correctly
> written code:)
Mr. Harmse probably didn't write either the spec or your compiler.
But the fact that even compiler writers can get this wrong does
demonstrate that this rule isn't obvious. One way to avoid misleading
people with less-than-obvious rules is to confine them to the section
of the spec which deals with that rule.
In my opinion, the example cited should be some void function
(so we don't have to return anything). Even if it is an int function,
it should NOT be function main().
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1998/09/03 Raw View
On 02 Sep 98 03:14:59 GMT, Steve Clamage <clamage@Eng.Sun.COM> wrote:
>But errors should be reported against the final standard, not against
>intermediate drafts.
Why isn't the final draft public? After all, the constitution of the
United States is public. Is it so that the standards committee can
fund its activities? This shouldn't be a concern here because a lot
of the big companies are involved in the C++ standardization, and it
would cost them nothing to fund the committees' activities.
--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: ark@research.att.com (Andrew Koenig)
Date: 1998/09/03 Raw View
In article <slrn6ur4of.p6j.sbnaran@localhost.localdomain>,
Siemel Naran <sbnaran@KILL.uiuc.edu> wrote:
> Why isn't the final draft public? After all, the constitution of the
> United States is public. Is it so that the standards committee can
> fund its activities?
You got it.
--
--
Andrew Koenig
ark@research.att.com
http://www.research.att.com/info/ark
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/09/04 Raw View
J. Harmse <harmse@galileo.tracor.com> wrote:
>> Implicit integer type should be removed from C, and should never have
>> been part of C++. That it's still legal is no excuse for using it.
You'll be happy to know that implicit int, and implicit function
declarations, have been removed from the next version of C (C9X).
As far as I know, C++ never allowed implicit int.
-- David R. Tribble, dtribble@technologist.com --
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/09/04 Raw View
In article <slrn6ur4of.p6j.sbnaran@localhost.localdomain>,
sbnaran@localhost.localdomain says...
> On 02 Sep 98 03:14:59 GMT, Steve Clamage <clamage@Eng.Sun.COM> wrote:
>
> >But errors should be reported against the final standard, not against
> >intermediate drafts.
>
> Why isn't the final draft public?
It is.
> After all, the constitution of the United States is public.
There are lots of places you can go to see copies of the U.S.
Constituion. If you want a copy of your own, you have to pay somebody
for a printed copy. Since it fits on one page and had a fairly wide
audience, copies are relatively inexpensive.
There are also places you can go to see a copy of the C++ standard for
free. If you want a copy of your own, you have to pay somebody for it
too. Since it occupies a LOT more pages, and has a MUCH smaller
audience, the price is, of course, considerably higher.
--
Later,
Jerry.
The Universe is a figment of its own imagination.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/09/04 Raw View
Jerry Coffin wrote:
>
>
> > After all, the constitution of the United States is public.
>
> There are lots of places you can go to see copies of the U.S.
> Constituion. If you want a copy of your own, you have to pay somebody
> for a printed copy. Since it fits on one page and had a fairly wide
> audience, copies are relatively inexpensive.
Andy Koenig experimented a bit at one of the standards meetings with
techniques for putting the C++ standard on one or two pages. The result
was interesting, but unacceptable: it was too hard to read. Putting the
U.S. Constitution on a single page would run into a similar problem. My
copy is 7 pages, plus 4 for the amendments. <g>
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]