views:

398

answers:

2

I'm trying to port code over to compile using Microchip's C18 compiler for a PIC microcontroller. The code includes enums with large values assigned (>8-bit). They are not working properly, indicating that, for example, 0x02 is the same as 0x2002.

How can I force the enumerated values to be referenced as 16-bit values?

A: 

In the DirectX headers, every enum has a FORCE_DWORD value in it with a value of 0xffffffff. I guess that's basically what you want, it forces to compiler to let the enum have at least 32 bits. So try adding a FORCE_WORD with a value of 0xffff.

This won't solve your problem, of course, if that compiler just does not support enums greater than 8 bits.

OregonGhost
A: 

I found the problem.

For future reference, the C18 compiler will NOT promote variables OR constants when performing a math operation, even though it is ANSI C standard. This is to increase speed while running on 8-bit processors.

To force ANSI compliance, use the "-Oi" compiler option.

See page 92 of the C18 manual.