www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/15/10:54:18

Date: Mon, 15 Jun 1998 17:51:07 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: sl <sl AT psycode DOT com>
cc: DJGPP mailing list <djgpp AT delorie DOT com>
Subject: Re: enum problem
In-Reply-To: <19980615072556700.AAA231@portC17.Generation.NET>
Message-ID: <Pine.SUN.3.91.980615174251.11003B-100000@is>
MIME-Version: 1.0

On Mon, 15 Jun 1998, sl wrote:

> #include <stdio.h>
> 
> enum lineType
> {
>   sLine=0x00,
>   dLine=0x01,
>   overwrite=0x02,
> };
> 
> void saychoice(lineType choice)
> {
>   if (choice|dLine==dLine)
>     printf("double line chosen");
>   if (choice|overwrite==overwrite)
>     printf("overwrite mode chosen");
> }
> 
> int main()
> {
>   saychoice(sLine|overwrite);
> }

There are several problems here.  First, compiling this as a C program 
didn't produce the warning you were complaining about.  So I suspect you 
compiled this as a C++ program, which you should have mentioned.  I'm 
quite sure that C++ produces an int from sLine|overwrite, and then 
objects to passing an int to a function which expects an enum.  But I'm 
not knowledgeable about C++ enough to tell for sure.  Anybody?

Second, what exactly did you expect from an expression like this:

	 if (choice|dLine==dLine)

At least in C, the == operator has higher precedence than the | operator, 
so this is parsed as "if (choice | (dLine == dLine))", which is hardly 
what you wanted to say...  Even if C++ changes that, I suggest to use 
explicit parentheses.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019