944,218 Members | Top Members by Rank

View Poll Results: What do you think of this compiler abnormality?
Good Thing 4 80.00%
Bad Thing 1 20.00%
Voters: 5. You may not vote on this poll

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3811
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 15th, 2006
0

Weird Stuff about Dev-C++ Compiler

Expand Post »
I use Bloodshed Dev-C++ version 4.9.9.2 and it is a little weird in that it accepts "and" as "&&" and "or" as "||", not to mention not requiring parentheses around separate clauses in and/or connected statements. Therefore it would read the following as the same.

if(voice==loud or voice==annoying and voice==whiny){
cout<<"SHUT UP!"<<endl;
}

if((voice==loud) || ((voice==annoying) && (voice==whiny))){
cout<<"SHUT UP!"<<endl;
}

Strange, huh?
Venomlash
Reputation Points: 86
Solved Threads: 2
Junior Poster
venomlash is offline Offline
143 posts
since Oct 2006
Oct 15th, 2006
2

Re: Weird Stuff about Dev-C++ Compiler

It's not an "abnormality," it's actually part of the C++ standard. As I understand it, operators like 'and' and 'or' are included for users with different character sets. See: http://david.tribble.com/text/cdiffs.htm#C99-alt-tok

Microsoft compilers appear to implement these as macros instead of keywords in the ciso646 header.

As for the second part of your post, the equality operator takes precedence over logical AND, which takes precendence over logical OR, so the parentheses aren't required in either case.
Reputation Points: 108
Solved Threads: 14
Junior Poster in Training
GloriousEremite is offline Offline
65 posts
since Jul 2006
Oct 16th, 2006
-1

Re: Weird Stuff about Dev-C++ Compiler

Best stick with && instead of "and" as you'll encounter problems if you switch compilers.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Best stick with && instead of "and" as you'll encounter problems if you switch compilers.
Again, it depends on which country you live in. Not all keyboards have a & key!!!! Actually "and" looks a lot more readable than "&&". Dev-C++ uses a much more international open source GNU compiler. Thank you GloriousEremite for the reference site!
Last edited by vegaseat; Oct 16th, 2006 at 3:04 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

I think he does have the & key. So therefore he should use it -if he wants to guarantee better portability.

If not I would expect him to have a little note saying, if you intend to use this code with such and such a compiler please include the relevant header.

>Not all keyboards have a & key!!!!
Can't ya just hold down [alt] + ### or whatever the number is for an ampersand?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

Click to Expand / Collapse  Quote originally posted by vegaseat ...
Again, it depends on which country you live in. Not all keyboards have a & key!!!! Actually &quot;and&quot; looks a lot more readable than &quot;&&&quot;. Dev-C++ uses a much more international open source GNU compiler.
As expected from a Python proponent But seriously, i agree with Mr. Iamthwee, its would be better NOT to use such keywords which are fully integrated in C++ standards but require the inclusion of a seperate header file #include <iso646.h>. So if you want your C++ code to be compatible with C standards, better stick to the && operator.
Quote ...
C90 does not have these built-in keywords, but it does provide a standard header file that contains definitions for the same words as macros, behaving almost like built-in keywords. The recommended practice for code intended to be compiled as both C and C++ is to use &quot;and&quot; identifiers only for special meanings, and only after including the header <iso646.h> .
Last edited by ~s.o.s~; Oct 16th, 2006 at 3:23 pm.
Super Moderator
Featured Poster
Reputation Points: 3244
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

ios646.h is apparently available in the C99 C standards. But I don't know how many compilers have implement those new C standards yet.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,966 posts
since Aug 2005
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

ios646.h is apparently available in the C99 C standards. But I don't know how many compilers have implement those new C standards yet.
I use Code::Blocks IDE which comes packed with the GCC Mingw compiler and the C File created in it does not recognize the C++ keywords.
Super Moderator
Featured Poster
Reputation Points: 3244
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

I use turbo c which crashes most of the time.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Oct 16th, 2006
0

Re: Weird Stuff about Dev-C++ Compiler

The C compiler that comes with Dev-CPP must be more modern ...
C++ Syntax (Toggle Plain Text)
  1. // using "and" and "or" rather than "&&" and "||"
  2. // as a Dev-Cpp C project
  3.  
  4. #include <stdio.h>
  5. #include <iso646.h> // yes this is needed!
  6.  
  7. int main()
  8. {
  9. int loud, annoying, whiny;
  10. int voice = 1;
  11.  
  12. loud = annoying = whiny = 1;
  13.  
  14. if (voice==loud or voice==annoying and voice==whiny)
  15. {
  16. printf("SHUT UP!\n");
  17. //cout<<"SHUT UP!"<<endl;
  18. }
  19. getchar();
  20. return 0;
  21. }
Turbo C??? I thought that was pretty bad 20 years ago!
Last edited by vegaseat; Oct 16th, 2006 at 4:30 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I dont know what mistake I did
Next Thread in C++ Forum Timeline: Passing parameters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC