gcc warnings
Tom St Denis
tstdenis@ellipticsemi.com
Wed Oct 17 11:49:00 GMT 2007
Humpolicek, Jiri - Acision wrote:
> Hi,
> I have, from my point of view, strange problem. I want to tell gcc to report all compilation warnings, especially warnings about assigment from variable of greater type to variable with smaller type. For example, when I write following code and compile it with next command no warning is reported:
>
> c++ -o test test.cpp -Wall -Wextra -Wconversion -pedantic
>
> #include "stdio.h"
>
> int main()
> {
> long a = 10000;
> unsigned char b = a;
>
> printf("%d\n", b);
>
> return b;
> }
>
>
The problem is that's not an error or problem as far as the C standard
[and C++] goes. So a warning for that while valid, would probably be
out of line.
My recommendation is to simply not assign across types unless you have
to. If you have a function like
void myfunc(unsigned long somevalue)
{
}
Then never store somevalue in anything but an unsigned long unless
you're sure of what you are doing. Why would you write
char careless = somevalue;
just for the hell of it?
Tom
More information about the Gcc-help
mailing list