Intel icc seems to think that enums are not ints:
#include <stdlib.h>
typedef enum { TRUE=1, FALSE=0 } Truth;
#undef __FUNCT__
#define __FUNCT__ "getcontrols"
int getcontrols(Truth *screen)
{
Truth flg=FALSE;
*screen = !flg;
return 0;
}
flg.c(10): warning #188: enumerated type mixed with another type
*screen = !flg;
^
But as far as I can read the standard, this should be perfectly
legitimate. Can anyone shed light on this?
Victor.
--
Victor Eijkhout -- eijkhout at tacc utexas edu 7 8915
In article <1h*************************@sig.for.address>,
Victor Eijkhout <se*@sig.for.addresswrote:
>Intel icc seems to think that enums are not ints:
>#include <stdlib.h> typedef enum { TRUE=1, FALSE=0 } Truth; #undef __FUNCT__ #define __FUNCT__ "getcontrols" int getcontrols(Truth *screen) {
Truth flg=FALSE;
*screen = !flg;
return 0; }
>flg.c(10): warning #188: enumerated type mixed with another type
*screen = !flg;
^
>But as far as I can read the standard, this should be perfectly legitimate. Can anyone shed light on this?
It's a warning message, not an error message. It's pointing
out to you that you are doing something that is suspect.
Compilers are allowed to emit any number of extra warnings
(as long as they compile programs that do not have constraint
violations).
--
Programming is what happens while you're busy making other plans.
(Walter Roberson) wrote:
>Victor Eijkhout wrote:
>>Intel icc seems to think that enums are not ints:
>>#include <stdlib.h> typedef enum { TRUE=1, FALSE=0 } Truth; #undef __FUNCT__ #define __FUNCT__ "getcontrols" int getcontrols(Truth *screen) { Truth flg=FALSE; *screen = !flg; return 0; }
>>flg.c(10): warning #188: enumerated type mixed with another type *screen = !flg; ^
>>But as far as I can read the standard, this should be perfectly legitimate. Can anyone shed light on this?
It's a warning message, not an error message. It's pointing out to you that you are doing something that is suspect. Compilers are allowed to emit any number of extra warnings (as long as they compile programs that do not have constraint violations).
In this case it is a useful warning. In the general case, enum types
are not semantically compatible, even if they are "all integers".
For example:
typedef enum { OPEN, CLOSED } valve_state;
typedef enum { RED, GREEN, BLUE } prim_color;
typedef enum { SPRING, SUMMER, FALL, WINTER } season;
typedef enum { SOLID, LIQUID, GAS, PLASMA } m_state;
int square(int num)
{
return num*num;
}
void nonsense(void)
{
int i;
valve_state v1 = OPEN;
if (LIQUID SUMMER)
{
i = square(CLOSED);
}
else
{
v1 = BLUE;
}
...
}
Roberto Waltman
[ Please reply to the group,
return address is invalid ]
Roberto Waltman <us****@rwaltman.netwrote:
typedef enum { RED, GREEN, BLUE } prim_color;
typedef enum { SPRING, SUMMER, FALL, WINTER } season;
typedef enum { SOLID, LIQUID, GAS, PLASMA } m_state;
int square(int num)
{
return num*num;
}
void nonsense(void)
{
int i;
valve_state v1 = OPEN;
if (LIQUID SUMMER)
{
i = square(CLOSED);
}
else
{
v1 = BLUE;
}
Yes I see your point about this being semantically nonsense. I still
think the compiler is being overly fussy: your example would have been
caught if only the enum->int cast was automatic. The other way would
indeed by objectionable.
Victor.
--
Victor Eijkhout -- eijkhout at tacc utexas edu
Victor Eijkhout wrote:
Roberto Waltman <us****@rwaltman.netwrote:
typedef enum { RED, GREEN, BLUE } prim_color;
typedef enum { SPRING, SUMMER, FALL, WINTER } season;
typedef enum { SOLID, LIQUID, GAS, PLASMA } m_state;
int square(int num)
{
return num*num;
}
void nonsense(void)
{
int i;
valve_state v1 = OPEN;
if (LIQUID SUMMER)
{
i = square(CLOSED);
}
else
{
v1 = BLUE;
}
Yes I see your point about this being semantically nonsense. I still
think the compiler is being overly fussy: your example would have been
caught if only the enum->int cast was automatic. The other way would
indeed by objectionable.
Your original example implicitly converted an int to an enum.
Victor Eijkhout wrote:
Roberto Waltman <us****@rwaltman.netwrote:
>>void nonsense(void) { int i; valve_state v1 = OPEN;
if (LIQUID SUMMER) { i = square(CLOSED); } else { v1 = BLUE; }
Yes I see your point about this being semantically nonsense. I still
think the compiler is being overly fussy: your example would have been
caught if only the enum->int cast was automatic. The other way would
indeed by objectionable.
I often disagree with my compiler about what should be warned. Many
compilers let you turn off specific warnings. Use that feature to
maximize you compiling experience! I make minor code changes "to make
the compiler happy" so I don't need to turn off lots of warnings.
--
Thad
On Fri, 16 Mar 2007 15:47:54 -0500, se*@sig.for.address (Victor
Eijkhout) wrote in comp.lang.c:
Roberto Waltman <us****@rwaltman.netwrote:
typedef enum { RED, GREEN, BLUE } prim_color;
typedef enum { SPRING, SUMMER, FALL, WINTER } season;
typedef enum { SOLID, LIQUID, GAS, PLASMA } m_state;
int square(int num)
{
return num*num;
}
void nonsense(void)
{
int i;
valve_state v1 = OPEN;
if (LIQUID SUMMER)
{
i = square(CLOSED);
}
else
{
v1 = BLUE;
}
Yes I see your point about this being semantically nonsense. I still
think the compiler is being overly fussy: your example would have been
caught if only the enum->int cast was automatic. The other way would
There is no such thing as an "automatic cast" or an "implicit cast" in
C. The only thing that ever performs a cast is a cast operator.
C has conversions. Some of them will occur automatically in
expression, on assignment, and on passing arguments to functions.
Others will only occur when a cast operator is used.
A cast is defined as an "explicit conversion". Any conversion that
occurs without the use of a cast operator is not any type of cast.
indeed by objectionable.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Thad Smith <Th*******@acm.orgwrote:
Many
compilers let you turn off specific warnings. Use that feature to
maximize you compiling experience!
That's what I've settled on. "icc -wr188"
I make minor code changes "to make
the compiler happy" so I don't need to turn off lots of warnings.
As do I. Unfortunately here I'm having to install a 1000-or-so-file
library, not written by me.
Victor.
--
Victor Eijkhout -- eijkhout at tacc utexas edu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: SpaceCowboy |
last post by:
I recently got into a discussion with a co-worker about using enums across a
dll interface. He wanted to use chars instead, argueing that depending on
compiler settings the size of an enum could...
|
by: David Rasmussen |
last post by:
The problem comes up in all sorts of contexts. But here is an example:
We want to model the basics of chess, maybe for making a chess program,
or maybe just to make an interactive board or ...
...
|
by: Mark A. Gibbs |
last post by:
i have been toying with the idea of making my enums smarter - ie, more
in line with the rest of the language. i haven't tested it yet, but what
i came up with is a template like this:
template...
|
by: Noah Roberts |
last post by:
I am having an interesting compilation error that makes me wonder if
enums can conflict with each other.
For example:
class A
{
enum X { TEST, TEST2 };
public:
....
|
by: Rajesh Abraham |
last post by:
I am running loop with calls different functions such as
SetHomeDrive, AddUserToGroup etc. Now if any of the
functions fails, I am just catching and throwing a new
error like throw new...
|
by: Craig |
last post by:
Newbie...
I'm casting enums back and forth to ints so to use them as an index into a
complex two dimensional array. I thought it would help readability.
Instead, my code has casts all over the...
|
by: Martin Pritchard |
last post by:
Hi,
I'm working on a project that historically contains around 40 enums. In the
database various fields refer to the int values of these enums, but of
course ref integrity is not enofrced and...
|
by: Cartoper |
last post by:
I am working in VS2005 (.Net 2.0).
I have a unmanaged C++ class that will be used by C#, once I get to
that point. I would like to throw a System::ApplicationException from
the unmanaged code,...
|
by: Spam Catcher |
last post by:
Hi all,
I have a usercontrol with a settable enum. How do I allow the user to edit
the enum through VS.NET's property panel?
The enum shows up, but it's not currently editable.
Thanks.
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |