C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Purpose of #define inside struct definition?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Tue May 08, 2007 9:12 am    Post subject: Purpose of #define inside struct definition? Reply with quote



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





PostPosted: Tue May 08, 2007 9:12 am    Post subject: Re: Purpose of #define inside struct definition? Reply with quote



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





PostPosted: Wed May 09, 2007 9:11 am    Post subject: Re: Purpose of #define inside struct definition? Reply with quote



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
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C Language All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group