Thread: Help with finding alternative to && operator

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    There is something as to making it too obfuscated. Now you're just creating unreadable code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Only now? I think both his last posts were an obfuscation, the later simply being worse.
    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"

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, the first required some thinking, but this one draws the line.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    He asked for an alternative, I provided an alternative. Can you say the same?

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    To be fair, it wasn't about an unreadable alternative. Everyone can do that.

    Code:
    #include <iso646.h>
    if (gross_income >= 2000 and gross_income <= 4000)
    There. Now I've provided and alternative. It just might not compile on all compilers, but it should be standard.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    I guess that's closer than mine. Seeing as it is an alternative for the operator, like he really asked for, not an expression that evaluates the same for a specific case(as my examples do). My point was to twist the expression around in a cool way, that happens to solve a particular problem, not to serve a purpose.

    A cool alt for (x != x) that I kinda based the second one off of: (x - x)

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    It just might not compile on all compilers, but it should be standard.
    There should also be #include <iso646.h>, and then this is a debatable alternative in that it is a macro that would be replaced by && anyway.

    Anyway, I agree that cyberfish probably has the right idea, if we assume a competent instructor. Saying that one provided an alternative is no defense for obfuscated code that misses the point when there has already been a sensible answer.

    EDIT:
    Quote Originally Posted by User Name:
    My point was to twist the expression around in a cool way, that happens to solve a particular problem, not to serve a purpose.
    Start your own contest. We have a contests board, if you were not aware. What you are doing here is basically showing off to a beginner who may be dangerously impressed.
    Last edited by laserlight; 07-22-2010 at 01:51 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by laserlight View Post
    There should also be #include <iso646.h>, and then this is a debatable alternative in that it is a macro that would be replaced by && anyway.
    True, but the instructor didn't say I couldn't use a standard macro, did he?

    I suppose you could also do
    Code:
    if ( !(gross_income <= 2000 || gross_income >= 4000) )
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    #include <iso646.h>
    if (gross_income >= 2000 and gross_income <= 4000)
    <Stroustrup> macro !!!
    <Stroustrup> macros are evil(TM)!!!

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    o_O
    In C++, they aren't macros. In C, they are. So blame whoever invented C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Whether it's a macro (as in C) or a keyword (as in C++), "and" in code is functionally equivalent to "&&". It might be argued that if you are using one, you are using the other, so changing "&&" to "and" is not a valid response to the question asked.

    One solution would be to use the old ternary operator.
    Code:
    if ((gross_income >= 2000)? (gross_income <= 4000) : 0)
    is - because of short circuiting that the operators support - functionally equivalent to
    Code:
    if (gross_income >= 2000 && gross_income <= 4000)
    I personally consider, of the two, the second is more readable.
    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. Some Interview questions, please help
    By higaea in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2010, 06:35 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. friendly assignment operator
    By Aidman in forum C++ Programming
    Replies: 2
    Last Post: 01-08-2007, 01:09 AM
  4. int vs BIG INT
    By rumi_red in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2001, 04:15 AM
  5. Overriding = operator.
    By Strahan in forum C++ Programming
    Replies: 4
    Last Post: 09-11-2001, 03:26 PM