Needed help on compiler option

Axel Freyn axel-freyn@gmx.de
Tue May 17 15:35:00 GMT 2011


Hi Subrahmanyam,

On Tue, May 17, 2011 at 04:18:40PM +0530, bhamidipati subrahmanyam wrote:
> [...]
> void test(int i)
> {
>     printf("i:%d\n",i);
> }
> 
> int main()
> {
>     char arr[100];
> 
>     arr[1] = 10;
> 
>     test(arr[1]);
> 
>     return 0;
> }
> 
> Logically, this code is working. But this simple concept resembles a
> real time problem, where the compiler should generate a warning when
> there is a type mismatch.

This code is valid C -- the compiler converts implicitly the char
"arr[1]" to the int i needed in the function's argument.

> 
> Pls suggest a compiler flag (flag like -Wall which should be passed to
> gcc) which should
> give a warning when there a type mismatch in the arguments t functions.
As far as I know, there is no option which would warn here (as the
conversion "char -> int" never changes the value). See also
http://gcc.gnu.org/wiki/NewWconversion
for a discussion of the flags -Wconversion and -Wtraditional-conversion

Axel



More information about the Gcc-help mailing list