Re: weird behavior of algbraic evaluation in concatenated operators

Discussion in 'C++' started by Prateek R Karandikar, Jul 2, 2004.

  1. dejan budimir wrote:
    > hi there!
    >
    > #include <iostream>
    > using namespace std;
    >
    > void main(){


    Illegal. main returns int. This should result in a diagnostic. Throw
    away any compiler that compiles such code.

    >
    > int i=0,
    > j=10;
    >
    > //Case one (the 'common' case):
    > cout<< "i == " << i << endl
    > << "j == " << j << endl;
    >
    > //Case two (the 'oddity'):
    > //Should print 1 and 11 (but will not evaluate the former expression
    > // before the latter, although it is printing in the correct order.
    > cout<< "(i+=1) == " <<(i+=1)<< endl
    > << "(j+=i) == " <<(j+=i)<< endl;


    i is being accesed twice, (of which one is for writing), without a
    sequence point in between them. Undefined behaviour.

    > }
    >
    > The ostream's operator<<() method is defined as to be passed only two
    > arguments a time, one of which must be the class, which is being
    > returned to allow concatenation.
    >
    > (cout<<expr1)<<expr2;
    >
    > But it seems as if the whole set of expressions is being evaluated,
    > _before_ becoming the arguments of the operator methods and, in
    > addition, is being evaluated from the right to the left (from the
    > stack?).


    The order of evaluation is unspecified.

    >
    > Is this a microsoft-specific way of dealing with concatenation?
    >
    > Havv ei got zee opchions wronk?


    -- --
    Abstraction is selective ignorance.
    -Andrew Koenig
    -- --
     
    Prateek R Karandikar, Jul 2, 2004
    #1
    1. Advertising

  2. "Prateek R Karandikar" <> wrote in message
    news:cc3t4d$...
    > dejan budimir wrote:
    > > hi there!
    > >
    > > #include <iostream>
    > > using namespace std;
    > >
    > > void main(){

    >
    > Illegal. main returns int. This should result in a diagnostic. Throw
    > away any compiler that compiles such code.
    >


    That is a little extreme. I have a compiler that compiles that code, my boss
    would be annoyed if I threw it away and refused to do any more work until he
    got me a better compiler.

    john
     
    John Harrison, Jul 2, 2004
    #2
    1. Advertising

  3. Prateek R Karandikar

    Mike Wahler Guest

    "Prateek R Karandikar" <> wrote in message
    news:cc3t4d$...
    > dejan budimir wrote:
    > > hi there!
    > >
    > > #include <iostream>
    > > using namespace std;
    > >
    > > void main(){

    >
    > Illegal. main returns int. This should result in a diagnostic. Throw
    > away any compiler that compiles such code.


    My car will allow me to drive it at high
    speed into a utility pole. Should I throw
    my car away? :)

    -Mike
     
    Mike Wahler, Jul 2, 2004
    #3
  4. "Mike Wahler" <> wrote in message news:W%eFc.2175$...
    > "Prateek R Karandikar" <> wrote in message
    > news:cc3t4d$...
    > > dejan budimir wrote:
    > > > hi there!
    > > >
    > > > #include <iostream>
    > > > using namespace std;
    > > >
    > > > void main(){

    > >
    > > Illegal. main returns int. This should result in a diagnostic. Throw
    > > away any compiler that compiles such code.

    >
    > My car will allow me to drive it at high
    > speed into a utility pole. Should I throw
    > my car away? :)


    My slightly-off-topic reply is...

    Yes.

    (I don't like cars. Never had one, never will. I walk,
    run, bike, or bus instead. Much cheaper, too.)

    I tend to take the same attitude towards compilers,
    debuggers, editors, etc. I've installed, evaluated,
    hated, and uninstalled quite a few. If it's annoying
    to use... it goes bye-bye. At least, on my computer.


    --
    Cheers,
    Robbie Hatley
    Tustin, CA, USA
    email: lonewolfintj at pacbell dot net
    web: home dot pacbell dot net slant earnur slant






    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Robbie Hatley, Jul 3, 2004
    #4
  5. * "Robbie Hatley" <lonewolfintj at pacbell dot net>:
    >
    > "Mike Wahler" <> wrote in message news:W%eFc.2175$...
    > > "Prateek R Karandikar" <> wrote in message
    > > news:cc3t4d$...
    > > > dejan budimir wrote:
    > > > > hi there!
    > > > >
    > > > > #include <iostream>
    > > > > using namespace std;
    > > > >
    > > > > void main(){
    > > >
    > > > Illegal. main returns int. This should result in a diagnostic. Throw
    > > > away any compiler that compiles such code.

    > >
    > > My car will allow me to drive it at high
    > > speed into a utility pole. Should I throw
    > > my car away? :)

    >
    > My slightly-off-topic reply is...
    >
    > Yes.


    It so happens that Visual C++ is one of those void main compilers.

    I wouldn't recommend throwing it away.

    If one were to throw away every compiler that doesn't conform to the HS
    in some way or other, then one would be left with exactly 0 compilers
    (or depending on the definition of conformance, only Comeau).

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jul 3, 2004
    #5
  6. Prateek R Karandikar

    Mike Wahler Guest

    "Robbie Hatley" <lonewolfintj at pacbell dot net> wrote in message
    news:40e640d6_2@127.0.0.1...
    >
    > "Mike Wahler" <> wrote in message

    news:W%eFc.2175$...
    > > "Prateek R Karandikar" <> wrote in message
    > > news:cc3t4d$...
    > > > dejan budimir wrote:
    > > > > hi there!
    > > > >
    > > > > #include <iostream>
    > > > > using namespace std;
    > > > >
    > > > > void main(){
    > > >
    > > > Illegal. main returns int. This should result in a diagnostic. Throw
    > > > away any compiler that compiles such code.

    > >
    > > My car will allow me to drive it at high
    > > speed into a utility pole. Should I throw
    > > my car away? :)

    >
    > My slightly-off-topic reply is...
    >
    > Yes.
    >
    > (I don't like cars. Never had one, never will.


    To each his own.

    > I walk,
    > run,


    Your legs will allow you to run at high speed
    into a utility pole. Should you throw your
    legs away?

    > bike,


    A bicycle will allow one to ride it at high
    speed into a utility pole. Should your throw
    your bicycle away? :)

    > or bus instead.


    A bus will allow its driver to drive it at high
    speed into a utility pole. Should you ride a
    bus?

    > Much cheaper, too.)
    >
    > I tend to take the same attitude towards compilers,
    > debuggers, editors, etc. I've installed, evaluated,
    > hated, and uninstalled quite a few. If it's annoying
    > to use... it goes bye-bye. At least, on my computer.


    You must lead a very frustrated life. Nothing is perfect,
    including you and I.

    -Mike
     
    Mike Wahler, Jul 3, 2004
    #6
  7. "Mike Wahler" <> wrote:

    > > I tend to take the same attitude towards compilers,
    > > debuggers, editors, etc. I've installed, evaluated,
    > > hated, and uninstalled quite a few. If it's annoying
    > > to use... it goes bye-bye. At least, on my computer.

    >
    > You must lead a very frustrated life.


    Quite the contrary. I find my approach simplifies things.

    > Nothing is perfect, including you and I.


    True, nothing are perfect. :)

    But the degree of imperfectness in things (incl.
    programming tools) varies dramatically. If I find
    myself cussing at a program and pounding my keyboard,
    it's time to click:

    Start / Settings / Control Panel / REMOVE Program


    --
    Cheers,
    Robbie Hatley
    Tustin, CA, USA
    email: lonewolfintj at pacbell dot net
    web: home dot pacbell dot net slant earnur slant
     
    Robbie Hatley, Jul 3, 2004
    #7
  8. Prateek R Karandikar

    JKop Guest

    Robbie Hatley posted:

    > Start / Settings / Control Panel / REMOVE Program



    Kind kind man.


    command

    cd\program files\

    deltree prog_in_question

    [y]


    -JKop
     
    JKop, Jul 3, 2004
    #8
  9. Prateek R Karandikar

    Old Wolf Guest

    "Prateek R Karandikar" <> wrote:
    > dejan budimir wrote:
    > >
    > > void main(){

    >
    > Illegal. main returns int. This should result in a diagnostic. Throw
    > away any compiler that compiles such code.


    The return type of main is implementation-defined. The worst you
    can say about "void main()" is that it is non-portable.
     
    Old Wolf, Jul 4, 2004
    #9
  10. Prateek R Karandikar

    Jack Klein Guest

    On 3 Jul 2004 16:00:52 -0700, (Old Wolf) wrote
    in comp.lang.c++:

    > "Prateek R Karandikar" <> wrote:
    > > dejan budimir wrote:
    > > >
    > > > void main(){

    > >
    > > Illegal. main returns int. This should result in a diagnostic. Throw
    > > away any compiler that compiles such code.

    >
    > The return type of main is implementation-defined. The worst you
    > can say about "void main()" is that it is non-portable.


    Not in C++ in a hosted environment. The standard states that
    specifically:

    ========
    3.6.1 Main function [basic.start.main]

    1 A program shall contain a global function called main, which is the
    designated start of the program. It is implementation-defined
    whether a program in a freestanding environment is required to define
    a main function. [Note: in a freestanding environment, startup
    and termination is implementation-defined; startup contains the
    execution of constructors for objects of namespace scope with static
    storage duration; termination contains the execution of destructors
    for objects with static storage duration. ]

    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.
    ========

    So "void main()" is _not_ just non-portable on a hosted C++
    implementation, it is a diagnosable error and makes the program
    ill-formed. It violates a "shall" clause.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Jul 4, 2004
    #10
  11. In message <2FvFc.3749$>, JKop <>
    writes
    >Robbie Hatley posted:
    >
    >> Start / Settings / Control Panel / REMOVE Program

    >
    >
    >Kind kind man.
    >
    >
    >command
    >
    >cd\program files\
    >
    >deltree prog_in_question
    >
    >[y]
    >

    Do you do that to the registry as well?

    --
    Richard Herring
     
    Richard Herring, Jul 5, 2004
    #11
  12. Prateek R Karandikar

    JKop Guest

    Richard Herring posted:

    > Do you do that to the registry as well?



    My way's more dramatic.

    The Windows System Registry is a mess already.


    -JKop
     
    JKop, Jul 5, 2004
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dejan budimir
    Replies:
    6
    Views:
    389
    Rolf Magnus
    Jul 4, 2004
  2. Ilias Lazaridis
    Replies:
    2
    Views:
    407
    Ilias Lazaridis
    Apr 24, 2005
  3. Ilias Lazaridis
    Replies:
    74
    Views:
    798
    Ilias Lazaridis
    Apr 4, 2005
  4. Ilias Lazaridis
    Replies:
    18
    Views:
    363
    Bill Guindon
    Apr 9, 2005
  5. Roy Smith
    Replies:
    6
    Views:
    177
    Chris Angelico
    Dec 3, 2012
Loading...

Share This Page