Topic: Could rvalue be bound to a non-const reference?


Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/12/10
Raw View
thp@vdo.ucr.edu (Tom Payne) writes:

>Steve Clamage (stephen.clamage@sun.com) wrote:

>: [The C++ standard] says in 3.6.1, paragraph 2:

>: ========
>: An implementation shall not predefine the main function. This function
>: shall not be overloaded. It shall have a return type of type int,
>: but otherwise its type is implementation-defined.
>: ========

>: Notice "shall have a return type of int". In standardese, "shall"
>: designates a requirement, not an option.

>If "shall" is imperative, what's up with that "but otherwise" clause?

The type of a function involves its return type, its linkage,
and the number and type of its arguments. The requirement here
is only on the return type.

As to number and type of arguments, the implementation must accept
both of
 int main() { ... }
 int main(int argc, char* argv[]) { ... }
and their equivalents, but can accept other forms as well.

--
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: stanley@West.sun.com (Stanley Friesen [Contractor])
Date: 1998/12/10
Raw View
In article <74oip2$opn$1@pravda.ucr.edu>, Tom Payne <thp@vdo.ucr.edu> wrote:
>
>Steve Clamage (stephen.clamage@sun.com) wrote:
>[...]
>: ========
>: An implementation shall not predefine the main function. This function
>: shall not be overloaded. It shall have a return type of type int,
>: but otherwise its type is implementation-defined.
>: ========
>
>: Notice "shall have a return type of int". In standardese, "shall"
>: designates a requirement, not an option.
>
>If "shall" is imperative, what's up with that "but otherwise" clause?
>
The *other* aspects of the type of main are left implementation defined.
That is the *parameter* list is implementation defined, as, in C++ the
parameter list is part of the type.

Thus a main declared as:

int main(char **, char **, char **)

is perfectly legal in C++ (if the implementation so allows), though not in C.


[ 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: Ron Natalie <ron@sensor.com>
Date: 1998/12/10
Raw View
Tom Payne wrote:
>
> It shall have a return type of type int,
> : but otherwise its type is implementation-defined.
> : ========
>
> : Notice "shall have a return type of int". In standardese, "shall"
> : designates a requirement, not an option.
>
> If "shall" is imperative, what's up with that "but otherwise" clause?

The "but otherwise" applies to to other aspects of the function
type other than the return type.  The type of a function includes
both the return type and the type of the arguments in C++.  The
return type SHALL be int, but the rest of the type might be anything.



[ 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/12/10
Raw View
In article <74oip2$opn$1@pravda.ucr.edu>,
  thp@vdo.ucr.edu (Tom Payne) wrote:
>
> Steve Clamage (stephen.clamage@sun.com) wrote:
> [...]
> : And what reference is that? This is newsgroup comp.STD.c++, and
> : the only suitable reference is the C++ standard. It says in
> : 3.6.1, paragraph 2:
>
> : ========
> : An implementation shall not predefine the main function. This function
> : shall not be overloaded. It shall have a return type of type int,
> : but otherwise its type is implementation-defined.
> : ========
>
> : Notice "shall have a return type of int". In standardese, "shall"
> : designates a requirement, not an option.
>
> If "shall" is imperative, what's up with that "but otherwise" clause?

Oh, come on! This one is obvious. "But otherwise" means "so long as
you don't break that rule, you may also obey the following clause."

"It shall have a return type of type int" -- specifies the return
type of the function, but not it's complete signature.

"but otherwise its type is implementation-defined" means that the
implementation is allowed to accept versions of main that accept
arbitrary arguments.

There is another requirement, not quoted above, that requires a
compiler to accept two specific signatures for main(), but the
implementation is allowed to expand that list.

--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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: thp@vdo.ucr.edu (Tom Payne)
Date: 1998/12/11
Raw View
AllanW@my-dejanews.com wrote:

: In article <74oip2$opn$1@pravda.ucr.edu>,
:   thp@vdo.ucr.edu (Tom Payne) wrote:
: >
: > Steve Clamage (stephen.clamage@sun.com) wrote:
: > [...]
: > : And what reference is that? This is newsgroup comp.STD.c++, and
: > : the only suitable reference is the C++ standard. It says in
: > : 3.6.1, paragraph 2:
: >
: > : ========
: > : An implementation shall not predefine the main function. This function
: > : shall not be overloaded. It shall have a return type of type int,
: > : but otherwise its type is implementation-defined.
: > : ========
: >
: > : Notice "shall have a return type of int". In standardese, "shall"
: > : designates a requirement, not an option.
: >
: > If "shall" is imperative, what's up with that "but otherwise" clause?

: Oh, come on! This one is obvious.
: "But otherwise" means "so long as
: you don't break that rule, you may also obey the following clause."

I tend to think of "otherwise" as referring to the negation of its
referrent.  Here it refers to those matters not mentioned by the
referrent.  For some reason, that became obvious only after the
correct meaning was pointed out.

Thanks,

Tom Payne


[ 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: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/12/11
Raw View
Tom Payne wrote:
>
> Steve Clamage (stephen.clamage@sun.com) wrote:
> [...]
> : And what reference is that? This is newsgroup comp.STD.c++, and
> : the only suitable reference is the C++ standard. It says in
> : 3.6.1, paragraph 2:
>
> : ========
> : An implementation shall not predefine the main function. This function
> : shall not be overloaded. It shall have a return type of type int,
> : but otherwise its type is implementation-defined.
> : ========
>
> : Notice "shall have a return type of int". In standardese, "shall"
> : designates a requirement, not an option.
>
> If "shall" is imperative, what's up with that "but otherwise" clause?

The type of a function is determined by more than its return type.
Especially it's determined by the argument types as well. This
is what the "but otherwise" tells: Except for the return type,
the implementation may decide to accept any type it wishes.

For example, the following main functions are allowed:

int main()
int main(int, char**)
int main(int, char**, char**)
int main(int, int, long, std::string)
int main(long, long, char*)
int main(long (*)(int))
int main(long, int, double)
int main(int, ...)
int main(__extensions::parameter_list)

(certainly ony one of them per program)

OTOH, the following are not allowed:

void main()
void main(int, char**)
long main()
short main()
double main()
int (*main())(int)
char* main()


[ 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: thp@vdo.ucr.edu (Tom Payne)
Date: 1998/12/10
Raw View
Steve Clamage (stephen.clamage@sun.com) wrote:
[...]
: And what reference is that? This is newsgroup comp.STD.c++, and
: the only suitable reference is the C++ standard. It says in
: 3.6.1, paragraph 2:

: ========
: An implementation shall not predefine the main function. This function
: shall not be overloaded. It shall have a return type of type int,
: but otherwise its type is implementation-defined.
: ========

: Notice "shall have a return type of int". In standardese, "shall"
: designates a requirement, not an option.

If "shall" is imperative, what's up with that "but otherwise" clause?

Tom Payne


[ 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/12/05
Raw View
bijuthom@ibm.net (Biju Thomas) wrote:

>Since there is a better word for specifying mandatory things in English,
>'must', why did the standard use the ambiguous 'shall'? It surely causes
>confusion to the uninitiated, at least the first time they see it. Is it
>something mandated by ISO?

"shall" is *exactly* the right word for designating something mandatory
in the future, and has been for hundreds of years. It is the standard way
of saying things in legal contexts, and the C++ Standard is a legal-type
document (viz the talk of "language lawyers").

For a 200+-year-old example, read the U.S. Constitution.

For a more recent verification, look at sense 1b in the American Heritage
Dictionary (3rd edition): "Something, such as an order, a promise, a
requirement, or an obligation. ... /The penalty shall not exceed two
years in prison./"

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
                      http://www.concentric.net/%7eBrownsta/
"I'm not even supposed to BE here!"  -- the mantra from /Clerks/
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: comeau@panix.com (Greg Comeau)
Date: 1998/12/05
Raw View
In article <747ntf$jem$1@oak.prod.itd.earthlink.net> "Vlad Vinogradsky" <vinogradsky@ibm.net> writes:
>
>Francis Glassborow wrote in message ...
>>>void main(int, char**)
>>>^^^^
>>>well with that in we aren't talking about C++ so anything is possible :)
>
>From the C++ language reference:
>
>"Program Startup: the main Function
>A special function called main is the entry point to all C++
>programs...Alternatively, the main and wmain functions can be declared as
>returning void (no return value). If you declare main or wmain as returning
>void, you cannot return an exit code to the parent process or operating
>system using a return statement; to return an exit code when main or wmain
>are declared as void, you must use the exit function."

wmain()?  Sounds like you are recifting from some sort of windows
manual, and not from Standard C++.  Standard C++ says that main()
shall have a return type of int.  Support should also be available for the
int main() and int main(int argc, char **argv) signatures.

- Greg
--
       Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
     Producers of Comeau C/C++ 4.2.38 -- New Release!  We now do Windows too.
    Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
                *** WEB: http://www.comeaucomputing.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: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/12/06
Raw View
In article <74a2ov$9pv$1@nnrp1.dejanews.com>, AllanW@my-dejanews.com
writes
>From the Collins English Gem Dictionary, 1954 edition:
>    must v. aux. Be obliged to, or certain to.
>
>    shall v. aux. Makes compound tenses or moods to express obligation,
>        command, condition or intention (should p.t.)
>
>    synonym n. Word with same meaning as another.
>
>I'd say must is a synonym to shall.

But this is not English, but a very specific dialect called
'standardese'.  One reason for that is that many people round the World
speak variants of English.  Sentences do not always mean the same thing
in different variants.



Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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: bitti@cs.tut.fi (Rintala Matti)
Date: 1998/12/04
Raw View
In article <747ntf$jem$1@oak.prod.itd.earthlink.net>
 "Vlad Vinogradsky" <vinogradsky@ibm.net> writes:
>   Francis Glassborow wrote in message ...
>   >>void main(int, char**)
>   >>well with that in we aren't talking about C++ so anything is possible :)
>
>   From the C++ language reference:
>   "Program Startup: the main Function
>   A special function called main is the entry point to all C++
>   programs...Alternatively, the main and wmain functions can be declared as
>   returning void (no return value).
...



Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/12/04
Raw View
In article <r4mtEJAxBxZ2Ewfp@robinton.demon.co.uk>, Francis Glassborow
<francis@robinton.demon.co.uk> writes
>>{
>>    A objA = foo(); // I think this should generate a compiler error?!
>
>Why? it says create objA as a copy of the return value of foo.
>I think you are confusing it with:
>
>A & A_ref = foo();
>
>as compared with:
>
>A const & A_cref = foo();
>>}

I realise that I had missed the fact that the original provided A(A&) as
the prototype for its copy ctor.   This is one of the principle reasons
why not providing A(A const &) is usually an mistake.

IMHO a decision not to provide the conventional copy ctor should always
be documented.


Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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/12/04
Raw View
In article <747ntf$jem$1@oak.prod.itd.earthlink.net>, Vlad Vinogradsky
<vinogradsky@ibm.net> writes
>From the C++ language reference:
>
>"Program Startup: the main Function
>A special function called main is the entry point to all C++
>programs...Alternatively, the main and wmain functions can be declared as
>returning void (no return value). If you declare main or wmain as returning
>void, you cannot return an exit code to the parent process or operating
>system using a return statement; to return an exit code when main or wmain
>are declared as void, you must use the exit function."

But this is comp.std.c++ and 3.6.1 para 2 sentence 3 starts 'It shall
have a return type of int ...'

There does not seem to be any option.


Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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/12/04
Raw View
In article <747ntf$jem$1@oak.prod.itd.earthlink.net>,
Vlad Vinogradsky <vinogradsky@ibm.net> wrote:

> From the C++ language reference:

> "Program Startup: the main Function
> A special function called main is the entry point to all C++
> programs...Alternatively, the main and wmain functions can be declared as
> returning void (no return value). If you declare main or wmain as returning
> void, you cannot return an exit code to the parent process or operating
> system using a return statement; to return an exit code when main or wmain
> are declared as void, you must use the exit function."

Ummm... which reference is this exactly?  Certainly not the
C++ standard, which does not contain the word `wmain' anywhere.
--
    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: "Vlad Vinogradsky" <vinogradsky@ibm.net>
Date: 1998/12/04
Raw View
I posted a slightly modified snippet of the actual code. Here, the call to
the copy constructor is optimized away - I think this is an example of NRV
optimization.

Temporary wrote in message <36670B98.4ECCF339@nothing.com>...
:
:Do you actually get the string "A(A&)" printed out? If so, that would be
really
:strange. On Sun CC and gcc, it looks like the compiler is optimizing the
copy
:constructor out of existence. I can't get either the incorrect, non-const
copy
:constructor or a real copy contructor to get fired.
:
:Interesting.



[ 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/12/04
Raw View
Vlad Vinogradsky wrote:
>
> Francis Glassborow wrote in message ...
> >>void main(int, char**)
> >>^^^^
> >>well with that in we aren't talking about C++ so anything is possible :)
>
> From the C++ language reference:
>
> "Program Startup: the main Function
> A special function called main is the entry point to all C++
> programs...Alternatively, the main and wmain functions can be declared as
> returning void (no return value). If you declare main or wmain as returning
> void, you cannot return an exit code to the parent process or operating
> system using a return statement; to return an exit code when main or wmain
> are declared as void, you must use the exit function."

This newsgroup is for the discussion of standard C++. A standard C++
compiler is allowed to accept main() with different parameter lists, but
regardless of the parameter list the return type must be 'int'. The
compiler whose reference manual you're quoting is describing it's
behavior when operating in a non-conforming mode.

In general, compiler reference manuals are a lousy source of information
on the C++ standard.


[ 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/12/04
Raw View
In article <747ntf$jem$1@oak.prod.itd.earthlink.net>,
  "Vlad Vinogradsky" <vinogradsky@ibm.net> wrote:
>
> Francis Glassborow wrote in message ...
> >>void main(int, char**)
> >>^^^^
> >>well with that in we aren't talking about C++ so anything is possible :)
>
> From the C++ language reference:

That's the language reference for one particular compiler, I take it.

> "Program Startup: the main Function
> A special function called main is the entry point to all C++
> programs...Alternatively, the main and wmain functions can be declared as
> returning void (no return value). If you declare main or wmain as returning
> void, you cannot return an exit code to the parent process or operating
> system using a return statement; to return an exit code when main or wmain
> are declared as void, you must use the exit function."

Compilers are allowed to make local extensions, but using this
feature makes your program non-portable.



Author: Biju Thomas <bijuthom@ibm.net>
Date: 1998/12/04
Raw View
In article <7481vq$o51$1@engnews2.Eng.Sun.COM>,
  stephen.clamage@sun.com (Steve Clamage) wrote:
>
> Notice "shall have a return type of int". In standardese, "shall"
> designates a requirement, not an option.
>

Since there is a better word for specifying mandatory things in English,
'must', why did the standard use the ambiguous 'shall'? It surely causes
confusion to the uninitiated, at least the first time they see it. Is it
something mandated by ISO?

Regards,
Biju Thomas

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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: "Vlad Vinogradsky" <vinogradsky@ibm.net>
Date: 1998/12/04
Raw View
You guessed it - it was VC++ on-line help:) Point taken. Thanks.

Vlad

Steve Clamage wrote in message <7481vq$o51$1@engnews2.Eng.Sun.COM>...

:And what reference is that? This is newsgroup comp.STD.c++, and

:the only suitable reference is the C++ standard. It says in
:3.6.1, paragraph 2: ...



[ 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/12/04
Raw View
Biju Thomas <bijuthom@ibm.net> writes:


>In article <7481vq$o51$1@engnews2.Eng.Sun.COM>,
>  stephen.clamage@sun.com (Steve Clamage) wrote:
>>
>> Notice "shall have a return type of int". In standardese, "shall"
>> designates a requirement, not an option.

>Since there is a better word for specifying mandatory things in English,
>'must', why did the standard use the ambiguous 'shall'? It surely causes
>confusion to the uninitiated, at least the first time they see it. Is it
>something mandated by ISO?

I remember from my school days that for second and third person
("thou, you" and "he, she, it, they"), "shall" is imperative.

Both ANSI and ISO prescribe standard terminology. For both, "shall"
designates a requirement.

--
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: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/12/04
Raw View
In article <36670B98.4ECCF339@nothing.com>, dontreply@nothing.com
says...
>
> Do you actually get the string "A(A&)" printed out? If so, that would be really
> strange. On Sun CC and gcc, it looks like the compiler is optimizing the copy
> constructor out of existence. I can't get either the incorrect, non-const copy
> constructor or a real copy contructor to get fired.

No -- you get:

A()
~A()

and everything else is optimized away.  I suspect this is why the
compiler allows the code by default; it does disallow it if you
disable their extensions, but that keeps the standard headers from
compiling, so it's only theoretically of any use.  I've been meaning
to try compiling up another standard library to see if I can make one
work with VC++ with extensions disabled, but I'm busy enough lately,
that this probably won't happen particularly soon.


[ 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/12/04
Raw View
In article <749a29$jt6$1@nnrp1.dejanews.com>,
Biju Thomas  <bijuthom@ibm.net> wrote:

> Since there is a better word for specifying mandatory things in English,
> 'must', why did the standard use the ambiguous 'shall'? It surely causes
> confusion to the uninitiated, at least the first time they see it. Is it
> something mandated by ISO?

Yes.  ISO also defines an official meaning for "must", which is to be
used only in contexts where any other alternative is impossible, not
merely prohibited.
--
    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: AllanW@my-dejanews.com
Date: 1998/12/05
Raw View
In article <749a29$jt6$1@nnrp1.dejanews.com>,
  Biju Thomas <bijuthom@ibm.net> wrote:
>
> In article <7481vq$o51$1@engnews2.Eng.Sun.COM>,
>   stephen.clamage@sun.com (Steve Clamage) wrote:
> >
> > Notice "shall have a return type of int". In standardese, "shall"
> > designates a requirement, not an option.
>
> Since there is a better word for specifying mandatory things in English,
> 'must', why did the standard use the ambiguous 'shall'? It surely causes
> confusion to the uninitiated, at least the first time they see it. Is it
> something mandated by ISO?



Author: AllanW@my-dejanews.com
Date: 1998/12/05
Raw View
In article <F3GIoK.JM6@research.att.com>,
  ark@research.att.com (Andrew Koenig) wrote:
>
> In article <749a29$jt6$1@nnrp1.dejanews.com>,
> Biju Thomas  <bijuthom@ibm.net> wrote:
>
> > Since there is a better word for specifying mandatory things in English,
> > 'must', why did the standard use the ambiguous 'shall'? It surely causes
> > confusion to the uninitiated, at least the first time they see it. Is it
> > something mandated by ISO?
>
> Yes.  ISO also defines an official meaning for "must", which is to be
> used only in contexts where any other alternative is impossible, not
> merely prohibited.

A quick grep on "must" suggests that the standard is rigorous about the
use of the word "must" in normative text, but extremely lax elsewhere.
Notes, examples and footnotes frequently use "must" instead of "shall."

--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


[ 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: "Vlad Vinogradsky" <vinogradsky@ibm.net>
Date: 1998/12/03
Raw View
Code below compiles without a problem on VC++ 5.0 and 6.0. I always thought
that rvalues (temporary of type A in this case) could not be bound to
non-const references. Am I wrong or this is just a compiler "feature"?

---------------------------------------------------------

#include <iostream>
using namespace std;

struct A
{
    A()   { cout << "A()\n"; }
    ~A()  { cout << "~A()\n"; }
    A(A&)  { cout << "A(A&)\n"; }
};

A foo()
{
    return A;
}

void main(int, char**)
{
    A objA = foo(); // I think this should generate a compiler error?!
}

--
Vlad Vinogradsky
RDA Consultants, Ltd. (www.rdaconsultants.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: "Andrei Alexandrescu" <alexandrescua@micromodeling.com>
Date: 1998/12/03
Raw View
Vlad Vinogradsky wrote in message
<746fal$cl2$1@ash.prod.itd.earthlink.net>...
>
>Code below compiles without a problem on VC++ 5.0 and 6.0. I always thought
>that rvalues (temporary of type A in this case) could not be bound to
>non-const references. Am I wrong or this is just a compiler "feature"?


Yeah, that's a "nonstandard extension". If you turn the warning level to
four, you'll see a warning.

Andrei




[ 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 Seitz" <mseitz@meridian-data.com>
Date: 1998/12/03
Raw View
Vlad Vinogradsky wrote in message
<746fal$cl2$1@ash.prod.itd.earthlink.net>...
>
>Code below compiles without a problem on VC++ 5.0 and 6.0. I always thought
>that rvalues (temporary of type A in this case) could not be bound to
>non-const references. Am I wrong or this is just a compiler "feature"?


The standard does not allow temporaries to be bound to non-const references.
Visual C++ allows it, but will generate a warning if you set the warning
level to 4.




[ 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: Temporary <dontreply@nothing.com>
Date: 1998/12/03
Raw View
Do you actually get the string "A(A&)" printed out? If so, that would be really
strange. On Sun CC and gcc, it looks like the compiler is optimizing the copy
constructor out of existence. I can't get either the incorrect, non-const copy
constructor or a real copy contructor to get fired.

Interesting.

John Daniel
(borrowing a WinNT machine - a real address is jdaniel@redwood.dn.hac.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: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1998/12/03
Raw View
In article <746fal$cl2$1@ash.prod.itd.earthlink.net>, Vlad Vinogradsky
<vinogradsky@ibm.net> writes
>#include <iostream>
>using namespace std;
>
>struct A
>{
>    A()   { cout << "A()\n"; }
>    ~A()  { cout << "~A()\n"; }
>    A(A&)  { cout << "A(A&)\n"; }
>};
>
>A foo()
>{
>    return A;
>}
>
>void main(int, char**)
 ^^^^
well with that in we aren't talking about C++ so anything is possible :)

>{
>    A objA = foo(); // I think this should generate a compiler error?!

Why? it says create objA as a copy of the return value of foo.
I think you are confusing it with:

A & A_ref = foo();

as compared with:

A const & A_cref = foo();
>}

Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ 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: "Vlad Vinogradsky" <vinogradsky@ibm.net>
Date: 1998/12/04
Raw View
Francis Glassborow wrote in message ...
>>void main(int, char**)
>>^^^^
>>well with that in we aren't talking about C++ so anything is possible :)



Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/12/04
Raw View
"Vlad Vinogradsky" <vinogradsky@ibm.net> writes:

>Francis Glassborow wrote in message ...
>>>void main(int, char**)
>>>^^^^
>>>well with that in we aren't talking about C++ so anything is possible :)

>From the C++ language reference:

>"Program Startup: the main Function
>A special function called main is the entry point to all C++
>programs...Alternatively, the main and wmain functions can be declared as
>returning void (no return value). If you declare main or wmain as returning
>void, you cannot return an exit code to the parent process or operating
>system using a return statement; to return an exit code when main or wmain
>are declared as void, you must use the exit function."

And what reference is that? This is newsgroup comp.STD.c++, and
the only suitable reference is the C++ standard. It says in
3.6.1, paragraph 2:

========
An implementation shall not predefine the main function. This function
shall not be overloaded. It shall have a return type of type int,
but otherwise its type is implementation-defined.
========

Notice "shall have a return type of int". In standardese, "shall"
designates a requirement, not an option.

--
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              ]