Thread: Writing a macro to compare two numbers?

  1. #16
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    >>Overloaded operators are functions, so there is no problem.
    Sure.
    The point is readability and it can cause confusion for maintainers.

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Bayint Naung View Post
    >>Overloaded operators are functions, so there is no problem.
    Sure.
    The point is readability and it can cause confusion for maintainers.
    I don't see how that's an issue here. This is perfectly reasonable code:
    Code:
    while( !cmp(array1[++run_length],value) );
    Last edited by King Mir; 06-28-2011 at 07:38 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by King Mir View Post
    I don't see how that's an issue here. This is perfectly reasonable code:
    Code:
    while(!cmp(array1[++run_lengh],value);
    Apart from missing closing bracket (which will typically trigger a compiler diagnostic) and misspelling of length, yeah.

    However, it is also quite reasonable to - as some coding guidelines do - stipulate that loop condition not have side effects, and code your particular loop as
    Code:
    while(!cmp(array1[run_length],value))
                  ++run_length;
    One (often intended) effect of such coding guidelines is that it reduces chances of using macros unsafely.

    Of course, the notion of "reasonableness" in code is subjective.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. writing a pair of numbers to an array
    By wankel in forum C Programming
    Replies: 53
    Last Post: 06-22-2009, 05:27 PM
  2. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  3. Writing a series of 8-bit numbers to disk with fwrite
    By thetinman in forum C Programming
    Replies: 16
    Last Post: 10-13-2006, 09:05 AM
  4. Help Writing My Own String Compare
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 04-07-2005, 09:44 PM
  5. Replies: 2
    Last Post: 09-11-2002, 05:00 PM