In one of the answers to a K&R exercise, the first couple of lines are:
enum loop { NO, YES};
enum loop okloop=YES;
I get the first line, but not the second.
Sorry about the LOL question.
Thanks in advance 37 2226
mdh wrote: In one of the answers to a K&R exercise, the first couple of lines are:
enum loop { NO, YES}; enum loop okloop=YES;
oklopp us a variable of the enum type loop, so you can assign either NO
or YES to it.
--
Ian Collins.
Ian Collins wrote: oklopp us a variable of the enum type loop, so you can assign either NO or YES to it.
It must be late or too much C :-)
I guess what I am missing is what the:
enum loop { YES,NO}
then does?
I thought that the idea behind this was to assign an integer to the
YES, NO? ( In this case 0 and 1?)
Then why not simply use the terms "YES" and "NO"?
Thanks in advance?
mdh wrote: Ian Collins wrote: oklopp us a variable of the enum type loop, so you can assign either NO or YES to it.
It must be late or too much C :-)
I guess what I am missing is what the:
enum loop { YES,NO}
then does?
An enum is a type, which in this case can have one of two values, YES
and NO.
Assigning any other value to a loop is undefined. Unfortunately C
compilers don't regard this as an error, which renders enums little more
than symbolic constants.
I thought that the idea behind this was to assign an integer to the YES, NO? ( In this case 0 and 1?)
Then why not simply use the terms "YES" and "NO"?
you can,
int n = YES;
Is perfectly OK.
--
Ian Collins.
mdh wrote: In one of the answers to a K&R exercise, the first couple of lines are:
enum loop { NO, YES}; enum loop okloop=YES;
I get the first line, but not the second.
Then separate the second line into its components:
enum loop okloop;
okloop = YES;
and the three lines are: type declaration, var declaration,
assignment.
--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"We have always known that heedless self-interest was bad
morals. We now know that it is bad economics" - FDR
CBFalconer wrote: Then separate the second line into its components:
Thank you both Ian and CBF for that explanation.
u can make use of okloop whereever u want "1"
if if is not that please correct me
venkatesh wrote: u can make use of okloop whereever u want "1" if if is not that please correct me
What are you replying to? Please quote the context.
Assuming you are refereing to:
enum loop { NO, YES};
enum loop okloop=YES;
You would use loop whenever you wanted YES. Use an enum for what it is,
if you wanted a synonym for 1, use a const (unsigned) int.
--
Ian Collins.
Ian Collins wrote: mdh wrote: Ian Collins wrote:
oklopp us a variable of the enum type loop, so you can assign either NO or YES to it.
An enum is a type, which in this case can have one of two values, YES and NO.
Assigning any other value to a loop is undefined. Unfortunately C compilers don't regard this as an error, which renders enums little more than symbolic constants.
gcc gives a warning when you do a switch on an enum type, indicating
that you have failed to explicitely specify behavior for any of the
listed cases. I find that very useful.
Bill Pursell wrote: Ian Collins wrote:
mdh wrote:
Ian Collins wrote:
oklopp us a variable of the enum type loop, so you can assign either NO or YES to it.
An enum is a type, which in this case can have one of two values, YES and NO.
Assigning any other value to a loop is undefined. Unfortunately C compilers don't regard this as an error, which renders enums little more than symbolic constants.
gcc gives a warning when you do a switch on an enum type, indicating that you have failed to explicitely specify behavior for any of the listed cases. I find that very useful.
But not with the following, which I've always considered a huge hole in
the C standard.
enum loop { NO, YES};
enum loop okloop=YES;
void f( enum loop v )
{
}
int main(void)
{
f( 42 );
okloop = 42;
return 0;
}
--
Ian Collins. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Harold Hsu |
last post by:
Hi,
Originally, I have defined the following Enum within a namespace (outside a
class):
Public Enum UserRole
Admin
Manager
User
End Enum
|
by: Jon Slaughter |
last post by:
is there a simple way to "step" through enums? I have a button that I want
to click and have it "cycle" through a set of states defined by enums but
the only way I can think of doing this "properly" yet "ugly" is to test the
state for each state. I know that enumes are not ordered but since they are
"stored" as numbers they have an inherent ordering which can be used. I
don't really care about the ordering though but just the ability to...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |