Like Tree4Likes
  • 1 Post By laserlight
  • 3 Post By iMalc

Assignment operator in C

This is a discussion on Assignment operator in C within the C Programming forums, part of the General Programming Boards category; In which version of C was the problem of = and == solved?...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    4

    Lightbulb Assignment operator in C

    In which version of C was the problem of = and == solved?

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    You don't need to spam up our board with pointless and na´ve questions. Are you trying to take a test or something?

    And what are you even talking about? There was never a problem with = and ==.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Posts
    39
    What is your question specifically?

  4. #4
    Registered User
    Join Date
    Jun 2012
    Posts
    4
    Sorry I misread the criticism section of C in wikipedia so the misconception.

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    39
    Look, I won't criticize you. Just please rephrase your question as it doesn't make any sense now.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Quote Originally Posted by SrikanthSuresh View Post
    In which version of C was the problem of = and == solved?
    It is not version of C - it your writing style
    If you always write the condition in form
    Code:
    if(0 == i)
    then compiler will give you error when you by mistake miss the = char
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Quote Originally Posted by vart
    If you always write the condition in form
    Except that you cannot always write the condition in that way since you may be comparing two non-const lvalues... unless you're really suggesting always ensuring that the left hand side is an rvalue or non-const lvalue, but if you can always remember that, then you can always remember not to use = when you mean ==.
    Salem likes this.
    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

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    or you can remember to use compiler which actually warns about using assigning operator inside if
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    It becomes a problem when I actually want to do an assignment and a boolean check at the same time. I wouldn't want future code maintainers to panic when those warnings pop up... possibly causing them to think I didn't know what I was doing.

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,167
    O_o

    (1): I submit that if your "maintainers" don't understand the definition of "false positive" they shouldn't be maintaining anything.

    (2): If your company standard has such extremes as "no warnings allowed even false positives" you shouldn't be combining assignment with the check in the first place.

    Soma

  11. #11
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    Heh, I was waiting for someone to tell me I was just coding wrong. Something like
    Code:
    if (fp = fopen(...)) {
        /* do good stuff since file open succeeded */
        }
    Compiler would whine telling me to dumb down my code. Oh well.

  12. #12
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Quote Originally Posted by nonoob View Post
    Heh, I was waiting for someone to tell me I was just coding wrong. Something like
    Code:
    if (fp = fopen(...)) {
        /* do good stuff since file open succeeded */
        }
    Compiler would whine telling me to dumb down my code. Oh well.
    The warning can usually be eliminated there by doing:
    Code:
    if ((fp = fopen(...)) != NULL) {
    Note that the extra brackets there are actually crucial to preventing the warning.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. assignment operator
    By acosgaya in forum C++ Programming
    Replies: 9
    Last Post: 02-20-2011, 08:47 AM
  2. assignment operator
    By dudeomanodude in forum C++ Programming
    Replies: 25
    Last Post: 03-06-2008, 12:14 PM
  3. assignment operator... i think
    By beene in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2007, 04:10 PM
  4. Assignment operator help.
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 02-10-2002, 09:15 PM
  5. Assignment operator
    By Claire in forum C++ Programming
    Replies: 3
    Last Post: 01-31-2002, 03:08 AM

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