Thread: && - and

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    && - and

    I wonder something for the operator: &&

    My question here is if it is possible to declare that if you write for example the word: and
    in the C++ code, this will meen: &&


    As for example when you declare something like this:
    int Number = 2;

    This meens when you write: Number, what you actually is writing is: 2
    Last edited by Coding; 01-12-2008 at 08:17 AM.

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Coding View Post
    I wonder something for the operator: &&

    My question here is if it is possible to declare that if you write for example the word: and
    in the C++ code, this will meen: &&


    As for example when you declare something like this:
    int Number = 2;

    This meens when you write: Number, what you actually is writing is: 2
    Do you mean like this:

    Code:
    std::string AND ="&&";
    ?

    Alternatively you could do this.

    Code:
    #define AND &&
    But why exactly are you trying to achieve this? What is the point?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    C++ should already allow you to use words instead of logical symbols (because not all keyboards have them). If your keyboard has those symbols, it might be better style to use them, though.

    Check out here.

    Your second question is not clear. You could do
    Code:
    #define Number 2
    or define an int constant Number that has the value 2 (preferred).
    Last edited by anon; 01-12-2008 at 08:30 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Yes this was what I was after, this function do work for this purpose:

    #define AND &&

    AND will have the same meening as && but just for a specific area in the code.
    Why I wanted to do this is because I will construct an own more "simplier" code language for easyuse so other people more easy can relate to the word "and" instead of &&.
    This "simplier" code language is for scanning .txt files in a specific way...
    Last edited by Coding; 01-12-2008 at 08:41 AM.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    58
    Why I wanted to do this is because I will construct an own more "simplier" code language for easyuse so other people more easy can relate to the word "and" as what is meen instead of &&.
    I read that using #define to make your own private language is a bad idea. Besides, who can read C++ but doesn't know what && means?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I agree, there is no gain whatsoever to this and coders may be confused because there is no keyword AND.
    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.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I use some applications that have done own codinglanguage using these approaches to define && to and. I beleive it is done to make it easier for people that dont know to much about coding and to adapt more easy to it. This funcion plus many more ofcourse but just for a specific area in the code.
    So I try to adapt this when also using the program I am trying to do..
    For me it will be easy to use && ofcourse but a few other people perheps wont.
    But now I know it is possible anyway, perheps I wont define it like this anyway...

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    With all due respect, if someone don't know how to program, they shouldn't be browsing the source.
    It's up to you to define things, of course, but in general I don't recommend it.
    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. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I also agree on that... If I do this I will do it with caution...

  10. #10
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Don't expect to many people to adopt this extension, though.

    With defines you can change the syntax of C++ to resemble other "simpler" languages, but such attempts generally result in WTF. Someone who learns your extension will be rather helpless if they need to switch to standard C++.

    Assuming descriptive variable names, AND and OR just add visual distraction IMO - or the statements using these operators are too complex anyway. In addition it won't help non-English programmers.

    And instead of defining upper-case versions, did you check out my link which says that "and" and others are already built-in synonyms in C++.

    Code:
    #include <iostream>
    
    #define WHILE(x) while(x) {
    #define WEND }
    #define PRINT(x) std::cout << x;
    
    int main()
    {
        int i = 1;
        WHILE(i != 10)
            PRINT(i)
            PRINT(" ")
            ++i;
        WEND
    }
    The point is that if you find C++ notation too confusing, but are rather happy about BASIC notation, for example, then rather than trying to turn C++ into BASIC you might better start coding in BASIC instead.
    Last edited by anon; 01-12-2008 at 09:16 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Someone who learns your extension will be rather helpless if they need to switch to standard C++.
    I will keep this in mind and perheps I wont define anything of the standardcode in the end.
    Thanks...

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Apparently in C++...
    Aye, anon mentioned this twice.
    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

  14. #14
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I haven't actually seen anyone use those keywords.

    My keyboard lay-out, for example, doesn't have a key for ^. Fortunately I need it seldom, but when I do, I rather type Alt + 094 than use bit_xor. With Code::Blocks even the Alt combination doesn't seem to work (?), so I resort to using the clipboard.

    If someone were programming on a keyboard that doesn't have any of these symbols, I'd understand the usage of synonyms.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, even if there's no such char, I'm sure there's a way to type it without using Alt+XXXX? It exists on most keyboards so far as I'm aware.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. str_replace && str_find
    By q6z4k in forum C Programming
    Replies: 12
    Last Post: 06-01-2008, 04:03 PM
  2. problem w/ color functions && win98 :P
    By DarkMortar in forum C Programming
    Replies: 2
    Last Post: 06-07-2006, 04:45 PM
  3. AnimateWindow && Dev-C++ problems
    By willc0de4food in forum Windows Programming
    Replies: 4
    Last Post: 03-13-2006, 04:34 PM
  4. [newb] How is "!(1 && !(0 || 1))" true?
    By eddwills in forum C++ Programming
    Replies: 11
    Last Post: 02-18-2006, 08:19 AM
  5. && or ||
    By chrismax2 in forum C++ Programming
    Replies: 4
    Last Post: 08-17-2005, 04:42 PM