Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make gcc warn implicit conversions [duplicate]

Tags:

c

gcc

warnings

Possible Duplicate:
Can I make GCC warn on passing too-wide types to functions?

Many times I cause bugs by passing a long to an integer function.

Can I make gcc warn me when I'm doing that?

like image 449
mikebloch Avatar asked Apr 21 '12 21:04

mikebloch


1 Answers

Try -Wconversion.

int fn(int);
int bar(long x) { return fn(x); }

gcc -c t.c  -Wconversion
t.c: In function ‘bar’:
t.c:3: warning: conversion to ‘int’ from ‘long int’ may alter its value
like image 101
Employed Russian Avatar answered Oct 25 '22 07:10

Employed Russian