Re: gcc warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux