Domanda

I have the following line of code:

uint32_t address = 0x40000000U;

This gives the following 3 PC-Lint errors when using the au-misra2.lnt configuration file:

"*** LINT: "D:\_SVN\LPC1788-32 Dev Kit\Bootloader--4\Loadware\source\led.c"(7, 35) Note 960: Violates MISRA 2004 Required Rule 10.1, Implicit conversion of integer to smaller type"

"*** LINT: "D:\_SVN\LPC1788-32 Dev Kit\Bootloader--4\Loadware\source\led.c"(7, 35) Info 712: Loss of precision (initialization) (unsigned long to unsigned int)"

"*** LINT: "D:\_SVN\LPC1788-32 Dev Kit\Bootloader--4\Loadware\source\led.c"(7, 35) Warning 569: Loss of information (initialization) (31 bits to 16 bits)"

Changing to:

uint32_t address = (uint32_t)0x40000000U;

Results in a value of 0 being assigned.

Why would this be happening? It is for a 32 bit Cortex-M3 processor so this should be assigning an unsigned int.. to an unsigned int - I cannot understand why it is not acceptable.

Does anyone have any ideas?

È stato utile?

Soluzione

It seems that PC-Lint is configured such that sizeof(int) equals 2. You can specify the sizeof(int) to PC-Lint with the -si# option. For example, use -si4 to specify that an int is 4 bytes.

Also, ensure that PC-Lint is using the proper include path and including the proper version of std_int.h.

Altri suggerimenti

The compiler may use a 16-bit instruction instead of a 32-bit to save code size. The default size for a literal is int, which may be only 16-bits. (I'm not sure.) The conversion error could then be from the literal itself before you cast it.

Try uint32_t address = 0x40000000UL;

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top