I have a project that uses gcc version 4.6.3, and I have to compile with "-Wall -Werror -Wconversion". The following simple example shows an error that I cannot get rid of:
#include <stdint.h> int main(void) { uint32_t u = 0; char c = 1; u += c; return (int)u; }
Compiling with the above flags gives:
test.c:7:8: error: conversion to 'uint32_t' from 'char' may change the sign of the result [-Werror=sign-conversion]
Good perfect. Just add a type, right? Nope. Changing line 7 to u += (uint32_t)c does not result in an error. Even changing it to u = u + (uint32_t)c does not make him leave.
Can this be fixed?
Note that "char" comes from a string, so I have no way to change its type.
c gcc casting
brooks94 Oct 19 '12 at 14:25 2012-10-19 14:25
source share