Is it possible to return a non-numbered Enumerated variable?

239 views
Skip to first unread message

Tom Iancovici

unread,
Mar 24, 2015, 11:01:31 AM3/24/15
to cppu...@googlegroups.com
Considering a case when you have a function that returns the kind of card it is

card_t takeCard(void)
{
        mock().actual("takeCard");

       return     <-----???
}

Is there a way to return an enumerated card_t that isn't numbered?  (i.e. typedef enum{spades, hearts, clubs, diamond} card_t)

or is it unavoidable? 

Heath Raftery

unread,
Mar 24, 2015, 3:36:58 PM3/24/15
to cppu...@googlegroups.com
Tom,

In fact, card_t is a number. C/C++ allows you to not specify the number, but as far as the compiler is concerned the statement is the same as:

typedef enum{spades=0, hearts=1, clubs=2, diamond=3} card_t;

So you could either return spades; or you could return (card_t)0;. Same thing.

In other words, no, it’s not possible to have an enumerated value which is not numbered.

Does that help?
Heath
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

James Grenning

unread,
Mar 24, 2015, 5:12:33 PM3/24/15
to cppu...@googlegroups.com
Hello Tom

How about this?

return (card_t)mock().actual("takeCard").returnValue().getIntValue();

BTW: did you know the posix standard has reserved all symbols that end
with _t?

James

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C -
pragprog.com/titles/jgade/
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)

James Grenning

unread,
Mar 24, 2015, 5:29:54 PM3/24/15
to cppu...@googlegroups.com
Oh sorry. I answered the wrong question it looks like.

Steven Collins

unread,
Mar 24, 2015, 5:31:55 PM3/24/15
to cppu...@googlegroups.com

On Tue, Mar 24, 2015 at 4:11 PM, James Grenning <ja...@grenning.net> wrote:
BTW: did you know the posix standard has reserved all symbols that end with _t?

I for one didn't. That sucks. I've used that convention for more years than I can count, and I'm sure that a lot of other folks have too. Looks like they made that grab back in '96. Pretty bad it took me nearly 20 years to hear about it!

"The GNU C Library implements all of the functions specified in ISO/IEC 9945-1:1996, the POSIX System Application Program Interface, commonly referred to as POSIX.1." 
http://www.gnu.org/software/libc/manual/html_node/POSIX.html#POSIX

"Some additional classes of identifier names are reserved for future extensions to the C language or the POSIX.1 environment."
...
"Names that end with ‘_t’ are reserved for additional type names." 
http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html

James Grenning

unread,
Mar 24, 2015, 6:05:49 PM3/24/15
to cppu...@googlegroups.com
I recently found out abut it too, though I was not a big _t user to
start with.

Of course, you can ignore the land grab :-)

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C -
pragprog.com/titles/jgade/
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)

Tom Iancovici

unread,
Mar 25, 2015, 7:28:12 AM3/25/15
to cppu...@googlegroups.com
Yes James that was it, I had to typecast it. 
Thanks

James Grenning

unread,
Mar 25, 2015, 2:18:11 PM3/25/15
to cppu...@googlegroups.com
Glad that helped!

James

On 25 Mar 2015, at 6:28, Tom Iancovici wrote:

> Yes James that was it, I had to typecast it.
> Thanks
>
> On Tuesday, March 24, 2015 at 5:12:33 PM UTC-4, James Grenning wrote:
>>
>> Hello Tom
>>
>> How about this?
>>
>> return (card_t)mock().actual("takeCard").returnValue().getIntValue();
>>
>> BTW: did you know the posix standard has reserved all symbols that
>> end
>> with _t?
>>
>> James
>>
>> --------------------------------------------------------------------------
>> James Grenning - Author of TDD for Embedded C -
>> pragprog.com/titles/jgade/
>> wingman-sw.com <http://pragprog.com/titles/jgade/wingman-sw.com>
>> wingman-sw.com/blog
>> twitter.com/jwgrenning
>> facebook.com/wingman.sw
>> [![wingman
>> software](
>> http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
>> On 24 Mar 2015, at 10:01, Tom Iancovici wrote:
>>
>>> Considering a case when you have a function that returns the kind of
>>> card
>>> it is
>>>
>>> card_t takeCard(void)
>>> {
>>> mock().actual("takeCard");
>>>
>>> return <-----???
>>> }
>>>
>>> Is there a way to return an enumerated card_t that isn't numbered?
>>> (i.e.
>>> typedef enum{spades, hearts, clubs, diamond} card_t)
>>>
>>> or is it unavoidable?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "cpputest" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send
>>> an email to cpputest+u...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages