Home > Mobile >  To add c header files in C header using C compiler?
To add c header files in C header using C compiler?

Time:06-14

I have a C header file, which I am including in a project running with a C compiler. and I have a few errors in the C header file since the syntaxes are different for both the compilers, obviously. But the hurdle is I should not modify the c header file. I tried using 'C' extern after reading from a few posts but seems the C compiler is not recognizing "__cplusplus".

is there any way that can be implemented in a C header file to include a C header file??

for eg. the C compiler is giving an error "Identifier 'Current' is undefined", because there is a 'struct' keyword missing in front of 'Current' in below code.

struct Current {
    uint16_t mini; 
    uint16_t maxi; 
    uint16_t counter; 
};  
struct someConstraint { 
    union { 
        Current ac_curr; 
    };
};

Please help and thank you !!

VP

CodePudding user response:

ISO C N2176 §6.2.2 Linkages of identifiers

  1. For an identifier […] If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.

You can typedef that struct:

typedef struct Current Current;
#include "somelib.h" // defines struct Current

Example on compiler explorer

CodePudding user response:

You could write your C code as is, and then use a C compiler to compile.

  • Related