Skip to contentSkip to conversation

question oh macros and gcc's intelligence

DISCUSSION Oliver Neukum 2 participants 2 messages Mar 17, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

if I write:

if (le16_to_cpu(p) == CONST) a();

is gcc smart enough to convert CONST to le16 and do a simple comparison?

Regards
Oliver

#1 lore raw
Quoted 8 lines · Oliver Neukum

Hi,

if I write:

if (le16_to_cpu(p) == CONST) a();

is gcc smart enough to convert CONST to le16 and do a simple comparison?

On little-endian - certainly, on big-endian - forget it.

	if (p == cpu_to_le16(CONST))

would obviously work on any architecture and yes, it would be a comparison with compile-time constant.