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

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.

commented: Good comment - Salem +3
commented: smart +5
Member Avatar for iamthwee

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

commented: narrow thinking -1

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!

Member Avatar for iamthwee

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?

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 :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 &quot;and&quot; identifiers only for special meanings, and only after including the header <iso646.h> .

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.

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.

Member Avatar for iamthwee

I use turbo c which crashes most of the time.

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!

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.

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.