Menu

Truncation because of Implicit Conversion

2016-09-29
2016-09-30
  • Jocris Bitoon

    Jocris Bitoon - 2016-09-29

    Hello,

    Does CPPCheck flag a warning when a possible truncation might happen due to implicit conversion of data types?
    Can it also be done for proprietary data types?

    Thanks!

     
  • Daniel Marjamäki

    Not currently.

    I do not want to have "lint" warnings about it. For instance whenever a 32-bit type is implicitly converted to 16-bit.

    like:

    void f(unsigned int x) {
        if (x < 10)
            short y = x;  // <- don't warn here!
    }
    

    But when there is actual truncation, it sounds good to warn. I think it should be relatively simple to add such warnings.

    example:

    void f() {
       unsigned int x = 0x12345;
       short y = x; // <- warn
    }
    
     

    Last edit: Daniel Marjamäki 2016-09-30

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.