Operator Precedence?

This is a discussion on Operator Precedence? within the C++ Programming forums, part of the General Programming Boards category; > But giving an example using functions instead of values is a little off topic since functions aren't mentioned in ...

  1. #31
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > But giving an example using functions instead of values is a little off topic since functions aren't mentioned in the Operator Precedence rules.
    If you wrote
    f + g * h;
    it wouldn't change anything, because evaluating a variable still involves say moving from a memory location to a register.

    > I guess that's why they just threw their hands up and said "ah screw it, lets just make it undefined".
    Pretty much.
    It's all to easy to argue that it might be possible to make something simple like ++x / x++ defined, but remember the spec assumes arbitrary complex expressions. If you had like 10 side effects on 6 different variables, you'd be in a much tougher spot.
    Then compiler writers would have a hell of a job writing and testing the code, and programmers would have a hard time understanding all the rules.

    As it stands, it's a very simple rule which is very unambiguous.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  2. #32
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Dave_Sinkula View Post
    Most garden variety charts show the function call operator in the list of operators.
    Yet another thing that's missing from that http://www.cppreference.com/ site...

  3. #33
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Are there any compilers that actually give you a warning that you're invoking undefined behavior?
    I tried compiling this on Comeau and VC++ with max warning levels, and neither of them said a word:
    Code:
    int main()
    {
       int x = 0;
       x = ++x / x++;
    
       return x;
    }

  4. #34
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    gcc:
    ../main.c:4: warning: operation on `x' may be undefined
    ../main.c:4: warning: operation on `x' may be undefined
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #35
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Dave_Sinkula View Post
    gcc:
    Cool. I wonder why the others don't complain?
    Another thing that gcc does that I wish VC++ would is that it tells you if you're missing some cases in a switch statement on an enum type.

  6. #36
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by cpjust View Post
    Another thing that gcc does that I wish VC++ would is that it tells you if you're missing some cases in a switch statement on an enum type.
    I believe PC-lint will do that.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #37
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    A command-line tool that costs $230. Wow. Even more expensive than Visual Assist X.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    A command-line tool that costs $230
    compiler is also command line tool... so? what's your point?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #39
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Elysia View Post
    A command-line tool that costs $230. Wow. Even more expensive than Visual Assist X.
    Heh. Amortize that over the cost of bugs.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #40
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Point was that it was expensive. Very much so.
    (And I cannot help but see how pretty much all recommended tools here are command-line based. PC-lint, gdb, valgrind, etc.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by Elysia View Post
    Point was that it was expensive. Very much so.
    (And I cannot help but see how pretty much all recommended tools here are command-line based. PC-lint, gdb, valgrind, etc.)
    Point is - the compiler used by VC is also command line tool - still you are recomending to use VC to compile code...

    the best feature of command line utils is - you can easely integrate them into the IDE you are using...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  12. #42
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > Point was that it was expensive. Very much so.
    Unless you're in the business of writing s/w, in which case $230 buys you a few hours of ONE engineer's time. Add up all those 'several hours' spent finding stupid bugs which pc-lint will find in a few seconds, and pretty soon it looks like a bargain.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #43
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Ya, for business maybe, but for a private dev (read: no business/company), it's very expensive for a software.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,712
    Ya, for business maybe, but for a private dev (read: no business/company), it's very expensive for a software.
    To put that in perspective, Visual Studio 2008 Standard edition costs $299. So, just as such a developer would be forced to do without PC-lint due to the cost issues, he/she would be forced to make do with Visual Studio 2008 Express edition, despite it being targeted at hobbyists and students instead of professional developers. That's life for a lone developer struggling to balance the budget, I guess
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #45
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Quote Originally Posted by laserlight View Post
    To put that in perspective, Visual Studio 2008 Standard edition costs $299. So, just as such a developer would be forced to do without PC-lint due to the cost issues, he/she would be forced to make do with Visual Studio 2008 Express edition, despite it being targeted at hobbyists and students instead of professional developers. That's life for a lone developer struggling to balance the budget, I guess
    Yeah, it's a shame. Thankfully there's Professional for students now
    But $230 is still a lot for some extra tools...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21