understanding a warning in RTEMS

Chris Johns chrisj@rtems.org
Sat May 9 23:05:00 GMT 2009


Hi,

We have this warning in RTEMS (the code is at the end of this email):

$ arm-rtems4.10-gcc -Wall -Wimplicit-function-declaration -Wstrict-prototypes 
-Wnested-externs -fasm -mcpu=arm7tdmi-s -mstructure-size-boundary=8 
-mapcs-frame -Wextra -Wno-unused -Wpointer-arith -Wcast-qual -Wconversion 
-Wmissing-prototypes -Os -g -c -o objwarning.o objwarning.c
objwarning.c: In function 'foo':
objwarning.c:26: warning: conversion to 'uint32_t' from 'int' may change the 
sign of the result

We are using gcc 4.4.0.

I do not understand the reason for the warning and was wondering if someone 
could please help explain it. It happens on all targets I have here to test on.

Why does a conversion from the uint16_t argument to a uint32_t only generate a 
warning when we have the extra types used in RTEMS ?


Regards
Chris


The code:

#include <stdint.h>

#define RTEMS_INLINE_ROUTINE static __inline__

typedef uint32_t   Objects_Id;
typedef uint16_t   Objects_Maximum;

#define OBJECTS_INDEX_START_BIT  0U
#define OBJECTS_INDEX_VALID_BITS (Objects_Id)0x0000ffffU

RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_index(
   Objects_Id id
)
{
   return
     (Objects_Maximum)((id >> OBJECTS_INDEX_START_BIT) &
                                           OBJECTS_INDEX_VALID_BITS);
}

RTEMS_INLINE_ROUTINE uint32_t _Objects_Get_index_2(
   Objects_Id id
)
{
   return (id >> OBJECTS_INDEX_START_BIT) & OBJECTS_INDEX_VALID_BITS;
}

uint32_t foo(Objects_Id id, Objects_Id minimum_id, uint16_t v);

uint32_t foo(Objects_Id id, Objects_Id minimum_id, uint16_t v)
{
   uint32_t    block;
   uint32_t    block_2;
   block = _Objects_Get_index( id ) - _Objects_Get_index( minimum_id );
   block_2 = _Objects_Get_index_2( id ) - _Objects_Get_index_2( minimum_id );
   return block + block_2;
}



More information about the Gcc-help mailing list