| | |
Header files, C++ vs C compiler question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
I am doing cross compiling between C++ and C compiler for header files and desperately need help on figuring out namespace issue error generated by C++ compiler.
Here are two header files:abc1.h, abc2.h and a C/C++ file containing the main().
When I compile this code on C, it works fine. However whenever I compile this on C++ compiler. It gives me the following error:
g++ -g -Wall cpptest.c -o cpptest
"abc2.h:3: error: using typedef-name ‘abc’ after ‘struct’
abc1.h:9: error: ‘abc’ has a previous declaration here"
I need to have both data structure available (struct _abc and struct abc)
someone typedef the _abc to abc inside abc1.h and I cannot change this file. I can only change abc2.h and the C/C++ file.
Anyone can explain to me why C++ compiler cannot accept this?
Anyone know of solution without changing abc1.h? (a work around)
Here are two header files:abc1.h, abc2.h and a C/C++ file containing the main().
When I compile this code on C, it works fine. However whenever I compile this on C++ compiler. It gives me the following error:
g++ -g -Wall cpptest.c -o cpptest
"abc2.h:3: error: using typedef-name ‘abc’ after ‘struct’
abc1.h:9: error: ‘abc’ has a previous declaration here"
I need to have both data structure available (struct _abc and struct abc)
someone typedef the _abc to abc inside abc1.h and I cannot change this file. I can only change abc2.h and the C/C++ file.
Anyone can explain to me why C++ compiler cannot accept this?
Anyone know of solution without changing abc1.h? (a work around)
C++ Syntax (Toggle Plain Text)
/*********** Header file abc1.h************/ #ifndef __ABC1__ struct _abc { int a; int b; }/*abc*/; /* if I comment out The line below and uncommented the abc above, it works well. typedef seems to be an issue in C++ compiler. However I can not touch this header file. */ typedef struct _abc abc; #endif
C++ Syntax (Toggle Plain Text)
/*********** Header file abc2.h************/ #ifndef __ABC2__ struct abc { char *c; void *d; }; #endif
C++ Syntax (Toggle Plain Text)
/* C/C++ file named abc.c or abc.cpp */ #include "abc1.h" #include "abc2.h" #include <stdio.h> int main() { printf("testing \n"); return 0; }
Last edited by toonces; Sep 7th, 2007 at 10:55 am.
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
I want to know if there is a work around and the reason why C++ compiler generates error while C compiler is fine with this.
I removed the comment from the abc1.h header file since it is not right.
/*********** Header file abc1.h************/
#ifndef __ABC1__
struct _abc
{
int a;
int b;
};
typedef struct _abc abc;
#endif
I removed the comment from the abc1.h header file since it is not right.
/*********** Header file abc1.h************/
#ifndef __ABC1__
struct _abc
{
int a;
int b;
};
typedef struct _abc abc;
#endif
![]() |
Similar Threads
- Visual studio (C++)
- Working with header files ??? (C)
- Header files (C++)
- doubt about header file implementation (C++)
- Does C++ indubitably have a standard? (C++)
- compile header file (C++)
- c vs h header files... (C)
- VMware help (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: MFC/ON_MESSAGE problem!!!
- Next Thread: Little bit of Homework Help would be greatly appreciated
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






