Menu

Cpp header in a C header

Erez Geva
2022-04-16
2023-06-20
  • Erez Geva

    Erez Geva - 2022-04-16

    Hi,

    I have a C header that is used by both C and C++ code.
    The C header includes a C++ header for C++ code using the '__cplusplus'
    precompile:

    ifdef __cplusplus

    #include "cpp_only_header.h"
    

    endif / __cplusplus /

    But when I do a "c" check
    cppcheck --language=c my_c.c

    I get an error of "cpp_only_header.h" using c++.

    I use
    $ cppcheck --version
    Cppcheck 2.3

    Any advice?
    Is this an issue?

    Thanks
    Erez

     
  • Daniel Marjamäki

    a quick hack that should work:

    cppcheck -U__cplusplus my_c.c
    

    Is this an issue?

    I think it's a little issue. I have created https://trac.cppcheck.net/ticket/10989

     
  • Daniel Marjamäki

    I can't reproduce any problems.

    Can you give some more details?

    The __cplusplus is skipped when I run this command:

    $ cppcheck 1.c
    Checking 1.c ...
    1.h:8:10: error: Division by zero. [zerodiv]
    int y=100/0;
             ^
    

    1.c:

    #include "1.h"
    

    1.h:

    #ifdef __cplusplus
    int x = 100/0;
    #endif
    int y = 100/0;
    
     

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.