Hi all!
As I said in the title, I have a very strange problem compiling a
program Here's the code that gives the problem:
enum letters
{
a = 0,
b,
c
};
typedef struct
{
letters let;
int number;
} someStruct;
It gives me an error before letters in the struct. Any idea on
what generates this error? I have to say that this was a C++ code, but
it doesn't use any class or anything else incompatible with C, at least
I think so.
Thanks for the help! 7 2071
Paolo wrote: Hi all! As I said in the title, I have a very strange problem compiling a program Here's the code that gives the problem:
enum letters { a = 0, b, c };
typedef struct { letters let; int number; } someStruct;
It gives me an error before letters in the struct. Any idea on what generates this error? I have to say that this was a C++ code, but it doesn't use any class or anything else incompatible with C, at least I think so.
I don't know about C++ (ask in comp.lang.c++), but in C an `enum` does
not define a type, so you'd need:
enum letters let;
in your structure.
--
BR, Vladimir
Paolo wrote: enum letters { a = 0, b, c };
typedef struct { letters let; int number; } someStruct;
typedef struct
{
enum letters let;
int number;
} someStruct;
or you could declare another typedef:
typedef enum letters letters_e;
then:
typedef struct
{
letters_e let;
int number;
} someStruct;
Thank you, I think I resolved. Another question, if I have a method
that returns an enum value, for example
letters GetFirstLetter(char* words);
do I have to add enum before letters?
Paolo wrote: Thank you, I think I resolved. Another question, if I have a method that returns an enum value, for example
letters GetFirstLetter(char* words);
do I have to add enum before letters?
IMHO yes. The word 'letters' alone doesn't denote a type, it must be
'enum letters' for it to be recognised as such. I always prefer
typedef(ing) enums and appending '_e', like 'letters_e'.
"Paolo" <pa****@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com... Hi all! As I said in the title, I have a very strange problem compiling a program Here's the code that gives the problem:
enum letters { a = 0, b, c };
If you want to use "letters" as a type name, as you do in someStruct below,
you have to typedef it.
typedef enum {
a=0,
b,
c
} letters;
typedef struct { letters let; int number; } someStruct;
It gives me an error before letters in the struct. Any idea on what generates this error? I have to say that this was a C++ code, but it doesn't use any class or anything else incompatible with C, at least I think so. Thanks for the help!
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
"Paolo" <pa****@gmail.com> writes: Thank you, I think I resolved. Another question, if I have a method that returns an enum value, for example
letters GetFirstLetter(char* words);
do I have to add enum before letters?
Yes, in C.
In your orinal post, you claimed that the code was C++ (which is
off-topic here, since /this/ group discusses only C). If that were
true, your code should have compiled (as would the above). It seems
very likely that you were compiling your "C++" code as C code, which
is why our solution worked. If it's really C++ code, make sure you're
compiling it with a C++ compiler. For implementations playing multiple
roles, this probably means you need to make sure your file ends in
..cc, .cx, or .C, rather than .c.
A lot of what I've just said is not really related to what we discuss
here on this newsgroup. If you would like your code to be C++ code,
and want to ask further questions about C++ code, ask
comp.lang.c++. If you want to ask how to get your compiler to compile
the code as C++ code, ask on a group related to your compiler.
HTH
Micah
"Vladimir S. Oka" <no****@btopenworld.com> writes: Paolo wrote: Hi all! As I said in the title, I have a very strange problem compiling a program Here's the code that gives the problem:
enum letters { a = 0, b, c };
[...] I don't know about C++ (ask in comp.lang.c++), but in C an `enum` does not define a type, so you'd need:
enum letters let;
in your structure.
Yes, an enum does define a type. The name of the type is
"enum letters", not "letters".
<OT>In C++, the type can be referred to as just "letters"; likewise
for classes, unions, and structs. This is one of the differences
between C and C++.</OT>
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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,...
|
by: Chris |
last post by:
I've lurked around long enough... Time to interract =)
I'm trying to make sense of the following. I can't quite wrap my head
around what this is actually doing:
-------------
typedef enum {...
|
by: Jerry |
last post by:
Hi,
I found an enum type, for example:
enum Alignment
{
Top,
Bottom
}
is derived Enum, but Enum is a struct. However,
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: Greg |
last post by:
Not sure if this is best place for this problem, but here it is. I have a
project that is simply a C# class that interfaces with an IFilter. This is
so I can retreive the text from Word docs. ...
|
by: PSL |
last post by:
Hi,
I am going through the training C# For Programmers made by TestOut and
like the presentation. The only problem is that this tutorial has a nastie bug
that renders this software practically...
|
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...
|
by: Don.Leri |
last post by:
Hi,
I have a logger.dll (unmanaged c++ dll compiled in vs2005).
I have a C# interop to use that dll in managed code implemented in
Interfaces.dll (used by other C# dlls).
I also have a...
|
by: desktop |
last post by:
When I try to compile this template I get an error in the line:
"enum { Yes = sizeof(IsClassT<T>::test<T>(0)) == 1};"
saying:
blop.hpp:8: error: expected primary-expression before ‘>’ token...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: 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...
|
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: 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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |