gcc -Wconversion

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

 



Hi

For our large 64-bit C++ project we use gcc compile options: -Wall -pedantic

We also build the project with Visual C++ and get lots of instances of
warning C4267, for example:

'initializing': conversion from 'size_t' to 'unsigned int', possible loss
of data

To get a similar warning with gcc it seems that I need -Wconversion.
However, that warning option seems very strict. For example with this code:

typedef struct
{
    uint8 x : 4,
             y  : 4;
} myHdr;

unsigned X=1;
myHdr hdr;

hdr.x = static_cast<uint8_t>(X);

I get warning:

warning: conversion to ‘unsigned char:4’ from ‘uint8_t {aka unsigned char}’
may alter its value [-Wconversion]

I have two questions:

1) What static_cast would I use to fix the above example warning?

2) Is -Wconversion recommended or is it too fussy in practice? Is there a
better option?

Best regards

David




[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