Thread: Operator Precedence?

  1. #31
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  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,005
    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,005
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    A command-line tool that costs $230
    compiler is also command line tool... so? what's your point?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  9. #39
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  12. #42
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  13. #43
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    28,413
    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
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #45
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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.

Popular pages Recent additions subscribe to a feed