Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. warning C4706: assignment within conditional expression

warning C4706: assignment within conditional expression

Scheduled Pinned Locked Moved The Weird and The Wonderful
help
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samuel Cragg
    wrote on last edited by
    #1

    I downloaded some code of the internet which is used as part of Firefox, OpenOffice etc, compiled it and it produced a few warnings. I'm not a fan of warnings so thought I'd have a look to fix it...

    if (((rv) &&
    ( checked_prefix || (words && words[wnum]) ||
    (compoundflag && TESTAFF(rv->astr, compoundflag, rv->alen)) ||
    ((oldwordnum == 0) && compoundbegin && TESTAFF(rv->astr, compoundbegin, rv->alen)) ||
    ((oldwordnum > 0) && compoundmiddle && TESTAFF(rv->astr, compoundmiddle, rv->alen))// ||
    // (numdefcpd && )

    // LANG\_hu section: spec. Hungarian rule
    || ((langnum == LANG\_hu) && hu\_mov\_rule && (
    TESTAFF(rv->astr, 'F', rv->alen) || // XXX hardwired Hungarian dictionary codes
    TESTAFF(rv->astr, 'G', rv->alen) ||
    TESTAFF(rv->astr, 'H', rv->alen)
    )
    )
    // END of LANG\_hu section
    ) &&
    (
    // test CHECKCOMPOUNDPATTERN conditions
    scpd == 0 || checkcpdtable\[scpd-1\].cond == FLAG\_NULL || 
    TESTAFF(rv->astr, checkcpdtable\[scpd-1\].cond, rv->alen)
    )
    && ! (( checkcompoundtriple && scpd == 0 && !words && // test triple letters
    (word\[i-1\]==word\[i\]) && (
    ((i>1) && (word\[i-1\]==word\[i-2\])) ||
    ((word\[i-1\]==word\[i+1\])) // may be word\[i+1\] == '\\0'
    )
    ) ||
    (
    checkcompoundcase && scpd == 0 && !words && cpdcase\_check(word, i)
    ))
    )
    // LANG\_hu section: spec. Hungarian rule
    || ((!rv) && (langnum == LANG\_hu) && hu\_mov\_rule && (rv = affix\_check(st,i)) &&
    (sfx && sfx->getCont() && ( // XXX hardwired Hungarian dic. codes
    TESTAFF(sfx->getCont(), (unsigned short) 'x', sfx->getContLen()) ||
    TESTAFF(sfx->getCont(), (unsigned short) '%', sfx->getContLen())
    )
    )
    )
    ) {
    	// 248 lines of code
    }
    

    In fairness, it's the first time I've seen so many comments inside an if statement! Think I'll live with the warning (i.e. disable it for that particular file.)

    M M L J 4 Replies Last reply
    0
    • S Samuel Cragg

      I downloaded some code of the internet which is used as part of Firefox, OpenOffice etc, compiled it and it produced a few warnings. I'm not a fan of warnings so thought I'd have a look to fix it...

      if (((rv) &&
      ( checked_prefix || (words && words[wnum]) ||
      (compoundflag && TESTAFF(rv->astr, compoundflag, rv->alen)) ||
      ((oldwordnum == 0) && compoundbegin && TESTAFF(rv->astr, compoundbegin, rv->alen)) ||
      ((oldwordnum > 0) && compoundmiddle && TESTAFF(rv->astr, compoundmiddle, rv->alen))// ||
      // (numdefcpd && )

      // LANG\_hu section: spec. Hungarian rule
      || ((langnum == LANG\_hu) && hu\_mov\_rule && (
      TESTAFF(rv->astr, 'F', rv->alen) || // XXX hardwired Hungarian dictionary codes
      TESTAFF(rv->astr, 'G', rv->alen) ||
      TESTAFF(rv->astr, 'H', rv->alen)
      )
      )
      // END of LANG\_hu section
      ) &&
      (
      // test CHECKCOMPOUNDPATTERN conditions
      scpd == 0 || checkcpdtable\[scpd-1\].cond == FLAG\_NULL || 
      TESTAFF(rv->astr, checkcpdtable\[scpd-1\].cond, rv->alen)
      )
      && ! (( checkcompoundtriple && scpd == 0 && !words && // test triple letters
      (word\[i-1\]==word\[i\]) && (
      ((i>1) && (word\[i-1\]==word\[i-2\])) ||
      ((word\[i-1\]==word\[i+1\])) // may be word\[i+1\] == '\\0'
      )
      ) ||
      (
      checkcompoundcase && scpd == 0 && !words && cpdcase\_check(word, i)
      ))
      )
      // LANG\_hu section: spec. Hungarian rule
      || ((!rv) && (langnum == LANG\_hu) && hu\_mov\_rule && (rv = affix\_check(st,i)) &&
      (sfx && sfx->getCont() && ( // XXX hardwired Hungarian dic. codes
      TESTAFF(sfx->getCont(), (unsigned short) 'x', sfx->getContLen()) ||
      TESTAFF(sfx->getCont(), (unsigned short) '%', sfx->getContLen())
      )
      )
      )
      ) {
      	// 248 lines of code
      }
      

      In fairness, it's the first time I've seen so many comments inside an if statement! Think I'll live with the warning (i.e. disable it for that particular file.)

      M Offline
      M Offline
      Monjurul Habib
      wrote on last edited by
      #2

      This is simply ridiculous.. :zzz: :zzz:

      1 Reply Last reply
      0
      • S Samuel Cragg

        I downloaded some code of the internet which is used as part of Firefox, OpenOffice etc, compiled it and it produced a few warnings. I'm not a fan of warnings so thought I'd have a look to fix it...

        if (((rv) &&
        ( checked_prefix || (words && words[wnum]) ||
        (compoundflag && TESTAFF(rv->astr, compoundflag, rv->alen)) ||
        ((oldwordnum == 0) && compoundbegin && TESTAFF(rv->astr, compoundbegin, rv->alen)) ||
        ((oldwordnum > 0) && compoundmiddle && TESTAFF(rv->astr, compoundmiddle, rv->alen))// ||
        // (numdefcpd && )

        // LANG\_hu section: spec. Hungarian rule
        || ((langnum == LANG\_hu) && hu\_mov\_rule && (
        TESTAFF(rv->astr, 'F', rv->alen) || // XXX hardwired Hungarian dictionary codes
        TESTAFF(rv->astr, 'G', rv->alen) ||
        TESTAFF(rv->astr, 'H', rv->alen)
        )
        )
        // END of LANG\_hu section
        ) &&
        (
        // test CHECKCOMPOUNDPATTERN conditions
        scpd == 0 || checkcpdtable\[scpd-1\].cond == FLAG\_NULL || 
        TESTAFF(rv->astr, checkcpdtable\[scpd-1\].cond, rv->alen)
        )
        && ! (( checkcompoundtriple && scpd == 0 && !words && // test triple letters
        (word\[i-1\]==word\[i\]) && (
        ((i>1) && (word\[i-1\]==word\[i-2\])) ||
        ((word\[i-1\]==word\[i+1\])) // may be word\[i+1\] == '\\0'
        )
        ) ||
        (
        checkcompoundcase && scpd == 0 && !words && cpdcase\_check(word, i)
        ))
        )
        // LANG\_hu section: spec. Hungarian rule
        || ((!rv) && (langnum == LANG\_hu) && hu\_mov\_rule && (rv = affix\_check(st,i)) &&
        (sfx && sfx->getCont() && ( // XXX hardwired Hungarian dic. codes
        TESTAFF(sfx->getCont(), (unsigned short) 'x', sfx->getContLen()) ||
        TESTAFF(sfx->getCont(), (unsigned short) '%', sfx->getContLen())
        )
        )
        )
        ) {
        	// 248 lines of code
        }
        

        In fairness, it's the first time I've seen so many comments inside an if statement! Think I'll live with the warning (i.e. disable it for that particular file.)

        M Offline
        M Offline
        makumazan84
        wrote on last edited by
        #3

        33 lines long condition in this piece of code is absolutely adorable! A drunk disassembler would have done a better job generating such code :) No kidding - recently, I had to restore some source code from a compiled dll, and reflector's result was way more reasonable than this one.

        O 1 Reply Last reply
        0
        • M makumazan84

          33 lines long condition in this piece of code is absolutely adorable! A drunk disassembler would have done a better job generating such code :) No kidding - recently, I had to restore some source code from a compiled dll, and reflector's result was way more reasonable than this one.

          O Offline
          O Offline
          oggenok64
          wrote on last edited by
          #4

          I've never seen this code before but assume it must be TKSpell. Yes, it's a horribly long conditional, but the code layout and comments make it reasonably clear as to what's happening. I know that i'm going to offend a lot of people, but a large function is not, repeat not, in itself a sign of bad programming. If the routine does exactly one well defined thing, it doesn't matter how large it is counting lines of code. And now i hear the refactoring crowd shouting at me. OK guys, you spend your time refactoring. I spend my time producing good solid production code.

          1 Reply Last reply
          0
          • S Samuel Cragg

            I downloaded some code of the internet which is used as part of Firefox, OpenOffice etc, compiled it and it produced a few warnings. I'm not a fan of warnings so thought I'd have a look to fix it...

            if (((rv) &&
            ( checked_prefix || (words && words[wnum]) ||
            (compoundflag && TESTAFF(rv->astr, compoundflag, rv->alen)) ||
            ((oldwordnum == 0) && compoundbegin && TESTAFF(rv->astr, compoundbegin, rv->alen)) ||
            ((oldwordnum > 0) && compoundmiddle && TESTAFF(rv->astr, compoundmiddle, rv->alen))// ||
            // (numdefcpd && )

            // LANG\_hu section: spec. Hungarian rule
            || ((langnum == LANG\_hu) && hu\_mov\_rule && (
            TESTAFF(rv->astr, 'F', rv->alen) || // XXX hardwired Hungarian dictionary codes
            TESTAFF(rv->astr, 'G', rv->alen) ||
            TESTAFF(rv->astr, 'H', rv->alen)
            )
            )
            // END of LANG\_hu section
            ) &&
            (
            // test CHECKCOMPOUNDPATTERN conditions
            scpd == 0 || checkcpdtable\[scpd-1\].cond == FLAG\_NULL || 
            TESTAFF(rv->astr, checkcpdtable\[scpd-1\].cond, rv->alen)
            )
            && ! (( checkcompoundtriple && scpd == 0 && !words && // test triple letters
            (word\[i-1\]==word\[i\]) && (
            ((i>1) && (word\[i-1\]==word\[i-2\])) ||
            ((word\[i-1\]==word\[i+1\])) // may be word\[i+1\] == '\\0'
            )
            ) ||
            (
            checkcompoundcase && scpd == 0 && !words && cpdcase\_check(word, i)
            ))
            )
            // LANG\_hu section: spec. Hungarian rule
            || ((!rv) && (langnum == LANG\_hu) && hu\_mov\_rule && (rv = affix\_check(st,i)) &&
            (sfx && sfx->getCont() && ( // XXX hardwired Hungarian dic. codes
            TESTAFF(sfx->getCont(), (unsigned short) 'x', sfx->getContLen()) ||
            TESTAFF(sfx->getCont(), (unsigned short) '%', sfx->getContLen())
            )
            )
            )
            ) {
            	// 248 lines of code
            }
            

            In fairness, it's the first time I've seen so many comments inside an if statement! Think I'll live with the warning (i.e. disable it for that particular file.)

            L Offline
            L Offline
            Lutoslaw
            wrote on last edited by
            #5

            Sam Cragg wrote:

            )
            )
            )
            )

            IHMO this is the best part of it.

            Greetings - Jacek

            1 Reply Last reply
            0
            • S Samuel Cragg

              I downloaded some code of the internet which is used as part of Firefox, OpenOffice etc, compiled it and it produced a few warnings. I'm not a fan of warnings so thought I'd have a look to fix it...

              if (((rv) &&
              ( checked_prefix || (words && words[wnum]) ||
              (compoundflag && TESTAFF(rv->astr, compoundflag, rv->alen)) ||
              ((oldwordnum == 0) && compoundbegin && TESTAFF(rv->astr, compoundbegin, rv->alen)) ||
              ((oldwordnum > 0) && compoundmiddle && TESTAFF(rv->astr, compoundmiddle, rv->alen))// ||
              // (numdefcpd && )

              // LANG\_hu section: spec. Hungarian rule
              || ((langnum == LANG\_hu) && hu\_mov\_rule && (
              TESTAFF(rv->astr, 'F', rv->alen) || // XXX hardwired Hungarian dictionary codes
              TESTAFF(rv->astr, 'G', rv->alen) ||
              TESTAFF(rv->astr, 'H', rv->alen)
              )
              )
              // END of LANG\_hu section
              ) &&
              (
              // test CHECKCOMPOUNDPATTERN conditions
              scpd == 0 || checkcpdtable\[scpd-1\].cond == FLAG\_NULL || 
              TESTAFF(rv->astr, checkcpdtable\[scpd-1\].cond, rv->alen)
              )
              && ! (( checkcompoundtriple && scpd == 0 && !words && // test triple letters
              (word\[i-1\]==word\[i\]) && (
              ((i>1) && (word\[i-1\]==word\[i-2\])) ||
              ((word\[i-1\]==word\[i+1\])) // may be word\[i+1\] == '\\0'
              )
              ) ||
              (
              checkcompoundcase && scpd == 0 && !words && cpdcase\_check(word, i)
              ))
              )
              // LANG\_hu section: spec. Hungarian rule
              || ((!rv) && (langnum == LANG\_hu) && hu\_mov\_rule && (rv = affix\_check(st,i)) &&
              (sfx && sfx->getCont() && ( // XXX hardwired Hungarian dic. codes
              TESTAFF(sfx->getCont(), (unsigned short) 'x', sfx->getContLen()) ||
              TESTAFF(sfx->getCont(), (unsigned short) '%', sfx->getContLen())
              )
              )
              )
              ) {
              	// 248 lines of code
              }
              

              In fairness, it's the first time I've seen so many comments inside an if statement! Think I'll live with the warning (i.e. disable it for that particular file.)

              J Offline
              J Offline
              jsc42
              wrote on last edited by
              #6

              The layout is not pretty and I would have commented it a lot more thoroughly, but there is nothing wrong with a complex if statement. I know that the refactoring polizei will feel that 1000 statements are better than one but as long as the code is well laid out and well commented (which this isn't), then a single statement can be simpler to follow. The warning, incidentally, is for the final stanza in the line after the comment // LANG_hu section: spec. Hungarian rule. The compiler is guessing that rv = affix_check(st,i) should be rv == affix_check(st,i)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups