473,466 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

enum and pointer help

63 New Member
Expand|Select|Wrap|Line Numbers
  1. enum state { dis =0, enable=8 }sta;
  2. struct SS {
  3. enum state *poin;
  4. }ss;
  5.  
  6.  
  7. main()
  8. {
  9. struct SS *str;
  10. str=&ss;
  11. printf("%d",(str->poin));
  12. }
  13.  
how to access the enum variable through "str "
Sep 18 '07 #1
4 1914
sicarie
4,677 Recognized Expert Moderator Specialist
Does that not work? What errors are you getting?

And PS - you are a member now, you should be using code tags around all of your code.

They are

[CODE=cpp] and [/code] with [CODE=cpp] before the start of your code and [/code] after the end. And, if you are using c, replace cpp with c. Thanks
Sep 18 '07 #2
askcq
63 New Member
how do I find the value of the next enum
.

is there any other method ??
Sep 18 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
An enum is a list of named integer values. It is not an array of variables.

You use:

Expand|Select|Wrap|Line Numbers
  1. state  var = enable;
  2. //instead of:
  3. state var = 8;
  4.  
If you display var you will see 8.

Therefore, in your struct SS you need to put the address of a state variable in the poin member:
Expand|Select|Wrap|Line Numbers
  1. SS str;
  2.   state  var = enable;
  3.   str.poin = &var;
  4.  
Sep 18 '07 #4
RRick
463 Recognized Expert Contributor
There are a couple of C style syntax's in the C++ program.

In C you need to use the struct and enum in the declaration of objects. In C++ you don't need this anymore. For example,
Expand|Select|Wrap|Line Numbers
  1. struct SS * ssPtr;            /*  C Style */
  2. enum state newState;
  3.  
  4. SS  * ssPtr;          // C++ Style
  5. state newState;
Both will work in C++, but the C++ style is more common.
Sep 18 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Alexander Grigoriev | last post by:
Not quite new version of GCC that I have to use, craps with the following code: enum E; enum E { e }; That is, it doesn't accept forward declaration of enum. C++ standard text doesn't...
5
by: Ernst Murnleitner | last post by:
Hello readers, I want to enumerate all values in an enum, e.g.: { enum Family{A=0, B,C, D = 100, E}; BaseItem * p = Factory::Get...// BaseItem is the basis of many other items // BaseItem...
3
by: Rob Jackson | last post by:
HiI've got a struct, known by file A.c, which contains a pointer to struct B. Struct B is unknown by file A.c (it is declared in C.h), and contains a typedef enum, which is declared in a file B.h,...
18
by: Nebula | last post by:
Consider enum Side {Back,Front,Top,Bottom}; enum Side a; Now, why is a = 124; legal (well it really is an integer, but still, checking could be performed..) ? Wouldn't enums be more useful if...
10
by: Russell Shaw | last post by:
Hi, gcc-3.4 complains about non-integers in: enum {IDENTIFIER = "<identifier>", WIDGETDEF = "widgetdef"}; even if i cast the strings to integers.
12
by: Laurent Deniau | last post by:
If I understand well, an enumeration is only garantee to hold at most an int (6.7.2.2-2). So I would like to know: how to store a long in an enum? enum { p2_31 = 1L << 31 }; // boom how to...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
5
by: Francois Grieu | last post by:
Does this reliably cause a compile-time error when int is not 4 bytes ? enum { int_size_checked = 1/(sizeof(int)==4) }; Any better way to check the value of an expression involving sizeof...
7
by: Travis | last post by:
Just curious, which takes less memory? enum Months { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC }; static const char *Months =
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.