analogdevicesinc / TMC-API

TRINAMIC's IC API
MIT License
188 stars 83 forks source link

Inconsistent variable initialization #12

Closed kaysievers closed 4 years ago

kaysievers commented 4 years ago

Here is a 32bit signed integer field:

typedef struct
{
    uint8_t address;
    int32_t value;
} TMCRegisterConstant;

Which gets several values assigned that do not fit into this data type:

{ 0x60, 0xAAAAB554 }, // MSLUT[0]
...
{ 0x64, 0xFBFFFFFF }, // MSLUT[4]
{ 0x65, 0xB5BB777D }, // MSLUT[5]
...

The compiler rightfully complains about this:

TMC2130.h:92:1: error: narrowing conversion of '2863314260' from 'unsigned int' to 'int32_t' {aka 'long int'} [-Wnarrowing]
   92 | };

Could the field be changed to unsigned, or a cast added to the initializer value to avoid this?

trinamic-LH commented 4 years ago

Fixed in b66f8f2df8551392156c85b1636ead3bf8439e22.