Demo of GBITX macros from Plan9 Fcall.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Try it out right in your web browser via GDB Online C compiler!

Demo of GBITX macros from Plan9 Fcall. These macros allow for extraction of one , two, three, or four bytes from memory address in pointer p. The extracted data is interpreted as unsigned char, unsigned short, unsigned int, or unsigned long int, respectively. This functionality is implemented via compiler preprocessor macros and bit shifts for efficiency.

Prototypes of the said macros are:

uchar      GBIT8(uchar*)
ushort     GBIT16(uchar*)
ulong      GBIT32(uchar*)
vlong      GBIT64(uchar*)

The definitions are:

#define	GBIT8(p) ((p)[0])
#define	GBIT16(p) ((p)[0]|((p)[1]<<8))
#define	GBIT32(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
#define	GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))

See also: // See also: