b***@gmail.com

2017-03-29 00:50:48 UTC

Hello All,

I am not a C expert by any means. I would like to understand this opensource code below. Can someone please explain the below declarations?

Please advise if there are other ways to self-learn these things for future reference.

# define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \

l|=(((unsigned long)(*((c)++)))<< 8), \

l|=(((unsigned long)(*((c)++)))<<16), \

l|=(((unsigned long)(*((c)++)))<<24))

/* NOTE - c is not incremented as per c2l */

# define c2ln(c,l1,l2,n) { \

c+=n; \

l1=l2=0; \

switch (n) { \

case 8: l2 =((unsigned long)(*(--(c))))<<24; \

case 7: l2|=((unsigned long)(*(--(c))))<<16; \

case 6: l2|=((unsigned long)(*(--(c))))<< 8; \

case 5: l2|=((unsigned long)(*(--(c)))); \

case 4: l1 =((unsigned long)(*(--(c))))<<24; \

case 3: l1|=((unsigned long)(*(--(c))))<<16; \

case 2: l1|=((unsigned long)(*(--(c))))<< 8; \

case 1: l1|=((unsigned long)(*(--(c)))); \

} \

}

# define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \

*((c)++)=(unsigned char)(((l)>> 8)&0xff), \

*((c)++)=(unsigned char)(((l)>>16)&0xff), \

*((c)++)=(unsigned char)(((l)>>24)&0xff))

# define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \

l|=((unsigned long)(*((c)++)))<<16, \

l|=((unsigned long)(*((c)++)))<< 8, \

l|=((unsigned long)(*((c)++))))

# define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \

l|=((uint64_t)(*((c)++)))<<48, \

l|=((uint64_t)(*((c)++)))<<40, \

l|=((uint64_t)(*((c)++)))<<32, \

l|=((uint64_t)(*((c)++)))<<24, \

l|=((uint64_t)(*((c)++)))<<16, \

l|=((uint64_t)(*((c)++)))<< 8, \

l|=((uint64_t)(*((c)++))))

I am not a C expert by any means. I would like to understand this opensource code below. Can someone please explain the below declarations?

Please advise if there are other ways to self-learn these things for future reference.

# define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \

l|=(((unsigned long)(*((c)++)))<< 8), \

l|=(((unsigned long)(*((c)++)))<<16), \

l|=(((unsigned long)(*((c)++)))<<24))

/* NOTE - c is not incremented as per c2l */

# define c2ln(c,l1,l2,n) { \

c+=n; \

l1=l2=0; \

switch (n) { \

case 8: l2 =((unsigned long)(*(--(c))))<<24; \

case 7: l2|=((unsigned long)(*(--(c))))<<16; \

case 6: l2|=((unsigned long)(*(--(c))))<< 8; \

case 5: l2|=((unsigned long)(*(--(c)))); \

case 4: l1 =((unsigned long)(*(--(c))))<<24; \

case 3: l1|=((unsigned long)(*(--(c))))<<16; \

case 2: l1|=((unsigned long)(*(--(c))))<< 8; \

case 1: l1|=((unsigned long)(*(--(c)))); \

} \

}

# define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \

*((c)++)=(unsigned char)(((l)>> 8)&0xff), \

*((c)++)=(unsigned char)(((l)>>16)&0xff), \

*((c)++)=(unsigned char)(((l)>>24)&0xff))

# define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \

l|=((unsigned long)(*((c)++)))<<16, \

l|=((unsigned long)(*((c)++)))<< 8, \

l|=((unsigned long)(*((c)++))))

# define n2l8(c,l) (l =((uint64_t)(*((c)++)))<<56, \

l|=((uint64_t)(*((c)++)))<<48, \

l|=((uint64_t)(*((c)++)))<<40, \

l|=((uint64_t)(*((c)++)))<<32, \

l|=((uint64_t)(*((c)++)))<<24, \

l|=((uint64_t)(*((c)++)))<<16, \

l|=((uint64_t)(*((c)++)))<< 8, \

l|=((uint64_t)(*((c)++))))