I’ve encountered the following couple of snippets of code in a source hive (ok, it’s Nethack) <br
that are causing me trouble regarding Bitfields and what appears to be some reflection going on. <br
Specific error is that BITFIELD is not recognized in XCODE, error comes up on the Bitfield definitions in the Struct. Is there a different way that would be largely compatible available that I'm not finding?
I used to be a professional C++ programmer a decade ago and this isn't how I'd do things at all.
//Definition - It appears that BITFIELDS is defined by default. This code snippets are verified from the nethack source globals.h
#ifdef BITFIELDS /* Force overriding Bitfields */
#define Bitfield(x, n) unsigned x : n
#else
#define Bitfield(x, n) uchar x
#endif
//Usage Snippet: from objclass.h
struct objclass {
short oc_descr_idx; /* description when name unknown */
char *oc_uname; /* called by user */
oc_name_known Bitfield(oc_name_known, 1); /* discovered */
Bitfield(oc_merge, 1); /* merge otherwise equal objects */ /*Reflection?*/
Bitfield(oc_uses_known, 1); /* obj->known affects full description;
otherwise, obj->dknown and obj->bknown
tell all, and obj->known should always
be set for proper merging behavior. */
};
I tried to compile the Nethack source
New contributor
user2024038 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.