Menu

Possibly confusing portability message on assignment

Luc Matt
2023-01-26
2023-01-27
  • Luc Matt

    Luc Matt - 2023-01-26

    I found a possible confusing message on portability, which after some tests I nailed down in this
    example, with questionable source code:

    File: try.c

    #define  P1ADDR     0x10000
    
    int     (*fn1)();
    long    (*fn2)();
    double  (*fn3)();
    
    void  foo(void)
    {
        fn1 = *(int    (*)())P1ADDR;
        fn2 = *(long   (*)())P2ADDR;
        fn3 = *(double (*)())P2ADDR;
    }
    

    Running cppcheck --enable=all . the result is as follows

    Checking try.c ...
    try.c:10:6: portability: Assigning an integer to a pointer is not portable. [AssignmentIntegerToAddress]
     fn1 = *(int    (*)())P1ADDR;
         ^
    try.c:8:0: style: The function 'foo' is never used. [unusedFunction]
    
    ^
    

    Note that the portability warning is issued only when I declare the pointer to a function returning an int,
    which is possibly misunderstood just as an int (given that message). The other assignments show no
    warning of any type, not even for style.
    I'm running both cppcheck version 2.8 and 2.9, on Win11 pro, with the same result.

     

    Last edit: Luc Matt 2023-01-26
  • CHR

    CHR - 2023-01-27

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11522

     

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.