 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Tue May 08, 2007 9:12 am Post subject: Purpose of #define inside struct definition? |
|
|
Following is a snippet of a header file.
Here, #define are inside struct evConn{}
Any advantage of putting them inside struct block?
Looks like there is no diff in scoping of each identifier between
inside and outside struct block....
typedef struct evConn {
evConnFunc func;
void * uap;
int fd;
int flags;
#define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
#define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
#define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
evFileID file;
struct evConn * prev;
struct evConn * next;
} evConn; |
|
| Back to top |
|
 |
Ian Collins Guest
|
Posted: Tue May 08, 2007 9:12 am Post subject: Re: Purpose of #define inside struct definition? |
|
|
djhong (AT) gmail (DOT) com wrote:
| Quote: | Following is a snippet of a header file.
Here, #define are inside struct evConn{}
Any advantage of putting them inside struct block?
|
Probably written this way to show the flags are associated with the
flags member of the struct.
| Quote: | Looks like there is no diff in scoping of each identifier between
inside and outside struct block....
typedef struct evConn {
evConnFunc func;
void * uap;
int fd;
int flags;
#define EV_CONN_LISTEN 0x0001 /* Connection is a listener. */
#define EV_CONN_SELECTED 0x0002 /* evSelectFD(conn->file). */
#define EV_CONN_BLOCK 0x0004 /* Listener fd was blocking. */
evFileID file;
struct evConn * prev;
struct evConn * next;
} evConn;
|
--
Ian Collins. |
|
| Back to top |
|
 |
Michal Nazarewicz Guest
|
Posted: Wed May 09, 2007 9:11 am Post subject: Re: Purpose of #define inside struct definition? |
|
|
Christopher Benson-Manica <ataru (AT) otaku (DOT) freeshell.org> writes:
| Quote: | Just from a style perspective, I might personally prefer these to be
#define EV_CONN_LISTEN ( 0x0001 << 0 ) /* Connection is a listener. */
#define EV_CONN_SELECTED ( 0x0001 << 1 ) /* evSelectFD(conn->file). */
#define EV_CONN_BLOCK ( 0x0001 << 2 ) /* Listener fd was blocking. */
to clearly indicate that they are bitmask flags, but I imagine this
isn't your code anyway - just a thought. (And to see how silly an
idea others feel this is.)
|
Personally, I find this method easier to edit. If I have like 20
masks it's easier to delete one from the middle or rearrange them when
they are written using (1 << n) idiom.
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>---<jid:mina86*chrome.pl>--ooO--(_)--Ooo-- |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|