473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

enum as return type

Hi,

is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?

Felix

typedef enum{
a_my_enum,
b_my_enum,
c_my_enum
}my_enum;

my_enum f2(void){
return a_my_enum;
}

void f(void){
my_enum e; /* ok? or must e by of type int? */
e=f2();
}
Dec 2 '06 #1
5 11219
Felix Kater wrote:
Hi,

is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?

Felix

typedef enum{
a_my_enum,
b_my_enum,
c_my_enum
}my_enum;

my_enum f2(void){
return a_my_enum;
}

void f(void){
my_enum e; /* ok? or must e by of type int? */
e=f2();
}
OK.

--
Eric Sosman
es*****@acm-dot-org.invalid
Dec 2 '06 #2

"Felix Kater" <fk****@googlemail.comwrote in message
news:20****************************@googlemail.com ...
Hi,

is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?

Felix

typedef enum{
a_my_enum,
b_my_enum,
c_my_enum
}my_enum;

my_enum f2(void){
return a_my_enum;
}

void f(void){
my_enum e; /* ok? or must e by of type int? */
e=f2();
}
Why didn't you just add:

int main(void)
{
return 0;
}

and try it?
Dec 2 '06 #3
Barry said:
"Felix Kater" <fk****@googlemail.comwrote in message
news:20****************************@googlemail.com ...
>is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?
<snip>
>
Why didn't you just add:

int main(void)
{
return 0;
}

and try it?
Because he wants to know whether it's valid C. Experimentation would only
give him empirical data, not proof of validity.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 2 '06 #4
Barry wrote:
"Felix Kater" <fk****@googlemail.comwrote in message
>>
is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?

typedef enum{
a_my_enum,
b_my_enum,
c_my_enum
}my_enum;

my_enum f2(void){
return a_my_enum;
}

void f(void){
my_enum e; /* ok? or must e by of type int? */
e=f2();
}

Why didn't you just add:

int main(void)
{
return 0;
}

and try it?
Because that doesn't answer the generic validity question.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

Dec 2 '06 #5
Felix Kater <fk****@googlemail.comwrites:
is it valid to declare the variable 'e' of type 'my_enum' to later hold
the return value of function f2 -- or must e by of type int?

Felix

typedef enum{
a_my_enum,
b_my_enum,
c_my_enum
}my_enum;

my_enum f2(void){
return a_my_enum;
}

void f(void){
my_enum e; /* ok? or must e by of type int? */
e=f2();
}
Yes, that's fine, and clearer than declaring e to be of type int.
Integer types and enum types can be freely assigned to each other.
In fact, enum constants (a_my_enum et al) are actually of type int.

--
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.
Dec 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
12
by: Steven T. Hatton | last post by:
Any opinions or comments on the following? I don't say it below, but I came out on the side of using enumerations over static constants. /* I'm trying to figure out the pros and cons of using...
2
by: Voronkov Konstantin | last post by:
Thank you for answer, but I still did not got *how* to make serialization of enum type. Can you provide more instructions or hint, please? My task is to serialize enum to something like byte...
6
by: randy1200 | last post by:
The following enum is given to me, and I can't change it: enum yo { ONE, TWO, THREE }; I have the following: char test = "ONE"; Any ideas on how to see if the string in "test" is in the...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
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...
35
by: dtschoepe | last post by:
Greetings. I am working on an assignment and can't seem to get the right concept for something I'm attempting to do with enum data types. I have defined the following in my code: enum color...
3
by: hufaunder | last post by:
Imagine you have a charting library that can draw lines, bars, floating bars, bands, etc. Lines and bars need only one input. Floating bars and bands need two inputs. There are two approaches: ...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.