954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Weird Stuff about Dev-C++ Compiler

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!"<

venomlash
Junior Poster
143 posts since Oct 2006
Reputation Points: 86
Solved Threads: 2
 

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.

GloriousEremite
Junior Poster in Training
65 posts since Jul 2006
Reputation Points: 108
Solved Threads: 14
 

Best stick with && instead of "and" as you'll encounter problems if you switch compilers.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
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!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

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?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 
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.


As expected from a Python proponent :D 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.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 "and" identifiers only for special meanings, and only after including the header .

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

I use turbo c which crashes most of the time.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

The C compiler that comes with Dev-CPP must be more modern ...

// using "and" and "or" rather than "&&" and "||"
// as a Dev-Cpp  C project

#include <stdio.h>
#include <iso646.h>  // yes this is needed!

int main()
{
  int loud, annoying, whiny;
  int voice = 1;
  
  loud = annoying = whiny = 1;
  
  if (voice==loud or voice==annoying and voice==whiny)
  {
    printf("SHUT UP!\n");
    //cout<<"SHUT UP!"<<endl;
  }
  getchar();  
  return 0;
}


Turbo C??? I thought that was pretty bad 20 years ago!

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 
[/code]Turbo C??? I thought that was pretty bad 20 years ago!

At one time it was one of the best MS-DOS compilers on the market -- Microsoft compilers really sucked cannel water in those days and NOBODY used their IDE. That was when Lattice C was king of the hill.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
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!

Please tell me you're kidding about the keyboards lacking an ampersand! I have never heard of that. Just to connect this to something funny, has anyone seen the Dilbert strip in which the company accidentally ships keyboards lacking the letter Q, marketing them under the slogan "The Big Q of Quality"? Bizarre, eh?
Venomlash

venomlash
Junior Poster
143 posts since Oct 2006
Reputation Points: 86
Solved Threads: 2
 

Well, it isn't really a good thing that and and && are the same to Dev, but it isn't really a problem if you just follow the rules of C++, now is it?

And even Visual Studio doesn't care if there are parentheses around independant clauses, but once again it's just good coding, so it shouldn't cause any problems.

FireSBurnsmuP
Posting Whiz in Training
237 posts since Sep 2006
Reputation Points: 46
Solved Threads: 2
 

The & is missing from keyboards in a number of European countries, as is the $ symbol. They however have other symbols they need on their keyboards.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You