Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido
Accepted Solution

C++ "and" operator????

This has me stumped. I've been programming professionally since the early 80's, and in the that time I've become fluent in a lot of lanquages and syntaxes... C/C++, C#, Java, Javascript, HTML, CSS, and many more. For about ten years I earned the bulk of my income doing contract PowerBuilder (PB) development. PB scripts are similar to Basic syntax, so "and" and "or" are written out explicitly, rather than symbols, like "&&" or "||" in C/C++.

 

With all those years working in PB it is inevitable that sometimes I type "and" in C++ instead of "&&", and I just rely on the compiler, or preferably the editor, to catch my mistake. What has me confused is that I was just troubleshooting an obscure bug in my Cascades app and I came across a conditional that looked like this:

 

if (var1 and var2) {
}

Which is clearly not valid C++ syntax, but neither the editor not compiler caught the mistake, and in fact, the code seems to run correctly (the condition is true if both var1 and var2 are true). The editor's syntax highlighter seems to think the "and" is another variable name since it colours "var2", "and", and "var2" all the same colour, but three variables in a row like that aren't valid C++ either.

 

I just can't figure out why this isn't caught by the compiler, at least, and why it seems to be equivalent to using the correct && operator. I suppose there could be a #define and && somewhere, but if so, I didn't put it there. Has anybody seen this?

 

BTW, this bad code has been in my app since I initially created it in March 2013, and was not caught by the 10.0, 10.1, or 10.2 SDKs.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: C++ "and" operator????

I was also surprised by this, but it seems these are standard C++ keywords. Smiley Happy

 

http://www.cplusplus.com/reference/ciso646/

 

iso646.h

This header defines eleven macro constants with alternative spellings for those C++ operators not supported by the ISO646 standard character set.

[...]

In C++, reserved words exist with the same names as these macros and are treated as aliases of their respective operator. Therefore the inclusion of this header has no effect in C++, and is not necessary in order to use the alternative names.


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: C++ "and" operator????

Wow, I've been developing with C++ since about 1990, and I didn't know this.

 


Zmey wrote:

I was also surprised by this, but it seems these are standard C++ keywords. Smiley Happy

 

http://www.cplusplus.com/reference/ciso646/

 

iso646.h

This header defines eleven macro constants with alternative spellings for those C++ operators not supported by the ISO646 standard character set.

[...]

In C++, reserved words exist with the same names as these macros and are treated as aliases of their respective operator. Therefore the inclusion of this header has no effect in C++, and is not necessary in order to use the alternative names.






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ "and" operator????


greenmr wrote:

Wow, I've been developing with C++ since about 1990, and I didn't know this.


If I remember my university lectures (which I don't Smiley Happy) when C++ was becoming popular and therefore the language to teach Object Oriented programming with (probably not these days) then they put it in to get round the problem of developers not neccesarily having *those* special characters on their keyboard that these keywords alias.

Of course my lecturers got a lot of things wrong. Smiley Happy


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: C++ "and" operator????

Sounds fishy to me, since I was around back when C++ was first getting popular, and the language of choice for teaching OO was SmallTalk since it was a truly "pure" OO language (everything, including the application, and basic types such as int, were objects). I think your prof may have been talking through his hat. LOL

 

However, I could buy into early terminals used for programming not having the "&" or "|" keys.


BBSJdev wrote:

greenmr wrote:

Wow, I've been developing with C++ since about 1990, and I didn't know this.


If I remember my university lectures (which I don't Smiley Happy) when C++ was becoming popular and therefore the language to teach Object Oriented programming with (probably not these days) then they put it in to get round the problem of developers not neccesarily having *those* special characters on their keyboard that these keywords alias.

Of course my lecturers got a lot of things wrong. Smiley Happy






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ "and" operator????

Perhaps my lecturers were more prescient than yours.

 

Mind you we also learnt ADA and Modula-2 and I never used those ever again. Smiley Happy

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,177
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: C++ "and" operator????

[ Edited ]

Did a small amount of work in Modula-2. A terrific language for its time, and designed as the logical successor to Pascal, which was never intended to be a production development tool. At a time when desktop PC's were all running single-tasking text-mode OSs (except the Amiga ) Modula-2 let you write preemptive multi-tasking applications painlessly.

 


BBSJdev wrote:

Perhaps my lecturers were more prescient than yours.

 

Mind you we also learnt ADA and Modula-2 and I never used those ever again. Smiley Happy

 

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.