gcc 4.3.0, -Wconversion and conditional operator

Andriy Gapon avg@icyb.net.ua
Fri Sep 19 17:09:00 GMT 2008


void f(int x)
{
         char c = x ? '|' : '/';
}


$ cc1: warnings being treated as errors
char.c: In function 'f':
char.c:3: error: conversion to 'char' from 'int' may alter its value
Exit 1

If I replace 'x' with a constant (0 or 1) in the condition, then the 
code compiles.
I think gcc should be smarter here.

-- 
Andriy Gapon



More information about the Gcc mailing list