Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22048

How can I avoid redefinition of types while including multiple header files?

$
0
0

I'm working on recompiling a C project and I'm not sure how do I fix this problem in a right way. Here is a situation -

a.h

#ifndef A_H
#define A_H
typedef int INT; 
// other variables and function definition
#endif

b.h

#ifndef B_H
#define B_H
typedef int INT;
// other variables and function definition
#endif

main.c

#include "a.h" 
#include "b.h"

int main()
{
    INT i = 10; 
    return 0;
}

The error I get in Linux with gcc:

In file included from ./main.c,

    ./b.h:<linenumber>: error: redefinition of typedef ‘INT’
    a.h.h:<linenumber>: note: previous declaration of ‘INT’ was here

I have to include both headers due to other variables and functions. I haven't written this code, but this seems to compile in my Solaris environment which is strange. What can I do to fix this ?


Viewing all articles
Browse latest Browse all 22048

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>