vendredi 28 février 2020

UINT32_T - values are getting changed

We have an embedded product in which we make use of small OS - it has its own header file where below is the declation for uint32_t in it's own header file:

#define ui32    unsigned int

While we have also added socket libraries where we have below declarations:

struct in_addr
{
  in_addr_t s_addr;     /* IPv4 address */
};

where

#define in_addr_t   uint32_t

Defined in stdint.h C++ library header file -

typedef unsigned int       uint32_t;

The problem I am facing is then when I assign value if uint32_t to ui32 I see some values getting changed:

struct in_addr ipl_addr;
.. assign some value ..

ui32 addr = ip_addr.s_addr
callme(addr)

When I debug the code I find that if the value of ip_addr.s_addr is 3456346304 in callme function the argument value is 65193 - however printing the value in the function of ui32 variable gives me 3456346304 but when used in if conditional statements I can see its value as 65193

Printing the sizeof both types is 4 - how the value getting changes and how can I protect the same - what compiler options we should use to error during compilation in such issues?

Aucun commentaire:

Enregistrer un commentaire