Question about macros

This is a discussion on Question about macros within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by laserlight Yes, assuming that the left hand expression is an rvalue or const. However, because this does ...

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by laserlight View Post
    Yes, assuming that the left hand expression is an rvalue or const. However, because this does not map to the usual way one would say it, I would argue that this would then make it harder "to read if you're skimming through the code quickly".
    To add to this (okay, so Desolation just pointed this out, some other fact I will point out)...
    USE WARNINGS (and a proper compiler).
    If you do something like:
    Code:
    if(something = NULL)
    Many compilers generate warnings at pedantic level, requesting you to put the expression in parenthesises to indicate it was actually what you wanted.

  2. #17
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by EVOEx View Post
    To add to this (okay, so Desolation just pointed this out, some other fact I will point out)...
    USE WARNINGS (and a proper compiler).
    If you do something like:
    Code:
    if(something = NULL)
    Many compilers generate warnings at pedantic level, requesting you to put the expression in parenthesises to indicate it was actually what you wanted.
    Warning Level 4 is all you need on Visual Studio to give you this warning.

    Quote Originally Posted by laserlight View Post
    Just to clarify: under what situations did your first company's coding standard mandate the comparison with a boolean literal?
    In all cases.
    I think it was mostly to prevent confusing code like:
    Code:
    if ( something != false )
    where they wanted it to be this instead:
    Code:
    if ( something == true )
    which I agree with completely.
    And also for consistency.

    They also required us to compile with the highest warning levels and to select the "Treat Warnings as Errors" option.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Quote Originally Posted by cpjust
    In all cases.
    hmm... but wouldn't that mean that in the case of a sentinel value, instead of writing:
    Code:
    bool is_valid = false;
    // ...
    if (is_valid)
    // ...
    you would have to write:
    Code:
    bool is_valid = false;
    // ...
    if (is_valid == true)
    // ...
    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

  4. #19
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by laserlight View Post
    hmm... but wouldn't that mean that in the case of a sentinel value, instead of writing:
    Code:
    bool is_valid = false;
    // ...
    if (is_valid)
    // ...
    you would have to write:
    Code:
    bool is_valid = false;
    // ...
    if (is_valid == true)
    // ...
    That's right.
    I think it's a lot easier to see:
    Code:
    if ( blah == false )
    than it is to see:
    Code:
    if ( !blah )
    especially on a friday evening when you barely got any sleep all week...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    Quote Originally Posted by cpjust
    That's right.
    I think it's a lot easier to see:
    That seems like a little of a straw man since "blah" is a poor name. With a descriptive name, I find that having to parse the extra "== true" or "== false" is harder, "especially on a friday evening when you barely got any sleep all week..."
    Compare "if the input is valid" and "if the input is not valid" with "if it is true that the input is valid" and "if it is false that the input is valid".
    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

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 07:52 PM
  2. Quick question about VB Word macros
    By PJYelton in forum Tech Board
    Replies: 6
    Last Post: 05-28-2005, 11:26 PM
  3. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Macros question
    By anson1999 in forum C Programming
    Replies: 12
    Last Post: 03-08-2003, 10:30 PM

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