<?= operator

This is a discussion on <?= operator within the C++ Programming forums, part of the General Programming Boards category; Hi, I have such code: Code: for(int i=0;i++<limit; maxx <?= rt + tt) { ... } Can anyone explan what ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    76

    <?= operator

    Hi,
    I have such code:
    Code:
    for(int i=0;i++<limit; maxx <?= rt + tt)
    	{
    ...
    	}
    Can anyone explan what does this operator <?= do?
    Thanks.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I don't think that's valid code. (Although it might be a digraph I don't know about.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    76
    Well, I compiled it and it works fine.
    Regards.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Ah! I know! <? is !. So <?= is the same as !=.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    76
    Thanks, is there any reason of using something like that ?

  6. #6
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by apacz
    Thanks, is there any reason of using something like that ?
    Obfuscation perhaps..

    There are contests to have the most obscure code, or simply to have the most obsure code (encrypted so it couldnt be understood )
    Last edited by Dae; 09-24-2005 at 04:20 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  7. #7
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Sweetie, '?' is the ternary operator, otherwise known as the conditional operator. It's called 'ternary' because it works with THREE operands...unlike something like '+' which works with two: (x+y).

    Code:
         int x=2, y=5, z=0; //Our three operands
         z = (x > y) ? (x:y); //Assign z to the bigger one.
    This is the alternative to if/else statements: it reads: "If x > y, assign x's value to z. Else, assign z the value of y."

  8. #8
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    How does that work in the situation its being used here?

    Code:
    maxx <?= rt + tt
    if maxx is 0, assign it to rt + tt? I'm confused already.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  9. #9
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    How does that work in the situation its being used here?

    Code:
    maxx <?= rt + tt
    if maxx is 0, assign it to rt + tt? I'm confused already.

    It cant be != like dwks said though, because its in the third section of the for statement..
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,618
    <? is described as a trigraph. The purpose of trigraphs is to allow programmers to work with keyboards that do not support certain characters. Most common scenario is on keyboards designed for non-english speakers (eg Scandinavian languages) <? expands to an exclamation mark (!)
    Last edited by grumpy; 09-24-2005 at 05:16 PM.

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    In this case it is indeed a digraph take means !

    However it is not defined in the standard so use at your own risk.

  12. #12
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    >>However it is not defined in the standard so use at your own risk.

    ok mom.

    why is everyone so anal about standard code?
    his own risk? a bit harsh a word considering all he wanted to know what what it meant.

    Ya, i'm just a bit annoyed right now at everyone harrassing me about "why are you writing it that way."
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by jrahhali
    why is everyone so anal about standard code?
    his own risk? a bit harsh a word considering all he wanted to know what what it meant.
    Because not everyone in the world uses the same compiler or OS. By following the standard you help ensure that the program will run as intended regardless of the machine. Of course there are times when the standard has to go out the window to solve a problem. However the likelyhood of someone posting a question on this board in which that would be the case is pretty slim.

    Now how about you tell me why you think you shouldn't follow the standard?

    Edit: Also about getting annoyed about people asking why you did something a certain way: Get used to it. You should be confident enough to explain exactly why you did something a particular way. And that doesn't go just for programming but for all areas of your work. When I worked as a switchboard tech I was asked quite regularly how I came to a conclusion and why I went with a particular path for solving the problem.

  14. #14
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    >>Now how about you tell me why you think you shouldn't follow the standard?

    But for his purposes, he wanted to know what it meant.

    edit: nvm..nvm. bye.
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  15. #15
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    When people say "use at your own" it doesnt just mean the OP, its anyone reading this to know that information. Also he is using that code apparently, and if using <? is unsafe I'm sure you would want to at least know.

    Anyway, question... what exactly the purpose of the third statement in this for loop?

    Code:
    for(int i = 0; i++ < limit; maxx != rt + tt)
    	{
    ...
    	}
    Its not even in the condition statement.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

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

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

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