Menu

macro definition in header file included in .c

michele
2018-02-02
2018-02-20
  • michele

    michele - 2018-02-02

    Hello,
    First of all I would like to thank you for the great job you are doing with cppcheck: we are using it since year and it's a great tool.

    I'm writing you because we often face an "information" when we have a macro defined in a header and we use it in a .c that includes that header: it seems like cppcheck it's not able to get the definition of the macro and it prints out "the value of 'MY_MACRO' is unknown".
    I prepared a simple example I attached: the "information" I get is

    Skipping configuration 'MY_MACRO' since the value of 'MY_MACRO' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

    I checked the forum and the manual but I cannot get how to get out of this error.
    Best Regards
    Michele

    Michele Ing. Corradin
    Group Technologic Development
    Sicon Srl
    tel. +39 (0)444 598803
    e-mail : michele.corradin@socomec.com

    [cid:3256544718_62773626]

    Sicon Srl
    Via Sila 1/3 - Zona Industriale Scovizze
    36033 Isola Vicentina (VI) ITALY
    http://www.socomec.comhttp://www.socomec.com/

    [signature_40ans_Sicon_200x92]
    P Prima di stampare, pensa all'ambiente ! Before printing, think about environment!


    Il contenuto di questa e-mail e dei file allegati è RISERVATO e da considerarsi utilizzabile solamente dalla persona o dall'ente cui è indirizzato. Se avete ricevuto questa e-mail per errore, siete pregati di rimandarla al mittente e di eliminarla (Legge italiana 196/2003).
    The content of this e-mail and of any attached files is CONFIDENTIAL and intended solely for the use of the individual or entity to whom it is addressed. If you have received this e-mail in error, please return it to the sender and delete it. (Italian Law 196/2003).

    This message and any attachments are established exclusively for his or its recipients, and are confidential. Any use, diffusion or unauthorized publication is prohibited. Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. SOCOMEC declines all responsibility concerning this message if it has been altered or tampered with. It normally contains no virus, but it is the responsibility of the recipient to ensure this. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the organization.

    Ce message et ses éventuelles pièces jointes sont établis à l'intention exclusive de son ou de ses destinataires et sont confidentiels. Toute utilisation, diffusion ou publication non autorisée est prohibée. Merci d'informer immédiatement l'auteur par retour de message si vous avez reçu ce message par erreur, et supprimez ce message. SOCOMEC décline toute responsabilité au titre de ce message s'il a été altéré ou falsifié. Il ne contient normalement aucun virus, mais il est de la responsabilité de son destinataire de s'en assurer. L'organisation décline toute responsabilité en ce qui concerne les informations fournies et les avis exprimés dans le présent message.

     
  • versat

    versat - 2018-02-05

    I can confirm this behaviour.
    Here is the output of analyzing the original a.c file and then analyzing b.c where the line with #error is commented out:

    cppcheck --enable=all --debug "a.c"
    Checking a.c ...
    Checking a.c: MY_MACRO...
    [a.c:16]: (information) Skipping configuration 'MY_MACRO' since the value of 'MY_MACRO' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
    
    cppcheck --enable=all --debug "b.c"
    Checking b.c ...
    [b.c:12]: (debug) valueflow.cpp:3134:valueFlowFunctionReturn bailout: function return; nontrivial function body
    
    ##file b.c
    
    1:
    |
    11:
    12: U32 fx ( )
    13: {
    14: U32 zVar@1 ;
    15:
    16: zVar@1 = $5 ;
    17:
    18: return 5 ;
    19: }
    
    ##Value flow
    Line 16
      5 always 5
    Line 18
      5 always 5
    [b.c:14]: (debug) Unknown type 'U32'.
    [b.c:12]: (style) The function 'fx' is never used.
    

    It seems like commenting out the line with #error and adding the line #define MY_MACRO 5 to a.c have similar effects.
    These tickets might be (slightly) related:
    https://trac.cppcheck.net/ticket/7917
    https://trac.cppcheck.net/ticket/6672
    https://trac.cppcheck.net/ticket/5112

    For me it looks like a defect. Somehow the preprocessor code

    #ifndef MY_MACRO
       #error "Define macro MY_MACRO"
    #endif
    

    might not be handled correctly when the definition of the macro is in a header.

     
  • michele

    michele - 2018-02-20

    thanks for your verification and support
    Michele

     
  • versat

    versat - 2018-02-20

    I created the ticket https://trac.cppcheck.net/ticket/8404 in the issue tracker.

     

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.