Groups | Search | Server Info | Login | Register
Groups > comp.lang.c.moderated > #527
| From | Toni Homedes i Saun <toni.homedes@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c.moderated |
| Subject | switch (long long) standard? |
| Date | 2014-04-01 01:50 -0500 |
| Organization | Usenet Fact Police |
| Message-ID | <clcm-20140401-0005@plethora.net> (permalink) |
Hi,
While developing a state machine compiler I came to a point where I would like the state machine to do a switch() based on current state + event, both being enums.
Would it be portable and standards compliant to do something similar to
enum states { ...... } current_state;
enum events { ...... } received_event;
#define INT_BITS (CHAR_BIT * sizeof (int))
#define mix(a,b) (((unsigned long long) (a)) << INT_BITS | (b))
.
.
.
switch (mix(current_state, received_event)) {
case mix(foo, bar) :
.....
break;
}
I don't have access to the standards so I can't check my assumptions but I understand that an enum is actually an int and that I need, at minimum, a long long to hold the value of two ints side by side. Is this correct?
And, what I really don't know, is if switch () can work on any size integral type or only on int
Thanks for any help
--
Toni
--
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
Back to comp.lang.c.moderated | Previous | Find similar
switch (long long) standard? Toni Homedes i Saun <toni.homedes@gmail.com> - 2014-04-01 01:50 -0500
csiph-web