473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Compiling C into C++

I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private". I've reproduced the problem
as follows:

/* -------- a.h - the C header file */
#ifndef TEST_H
#define TEST_H

struct s
{
void *private;
};

#endif
/* -------- end a.h */
/* -------- b.cpp - the C++ header file trying to include a.h */
extern "C" {
#include "a.h"
}
/* -------- end b.cpp */

I am compiling using this command:

%g++ -o b.o b.cpp

Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?

Apr 11 '07 #1
5 4244
<jo***********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private". I've reproduced the problem
as follows:

/* -------- a.h - the C header file */
#ifndef TEST_H
#define TEST_H

struct s
{
void *private;
};

#endif
/* -------- end a.h */
/* -------- b.cpp - the C++ header file trying to include a.h */
extern "C" {
#include "a.h"
}
/* -------- end b.cpp */

I am compiling using this command:

%g++ -o b.o b.cpp

Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?
Well, I don't think you're doing anything wrong, it's just that private
became a keyword in C++. What I would probably do is change the variable
name of private in the header file to something else. Something like:

#ifndef TEST_H
#define TEST_H

#define private priv

// file here

#undef private
#endif

This should have the effect of changing all occurances of "private" in that
header to "priv" wihtout having to modify the header file beyond that two
precompiler directives.
Apr 11 '07 #2
On Apr 11, 4:25 pm, jois.de.vi...@gmail.com wrote:
I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private". I've reproduced the problem
as follows:

/* -------- a.h - the C header file */
#ifndef TEST_H
#define TEST_H

struct s
{
void *private;

};

#endif
/* -------- end a.h */

/* -------- b.cpp - the C++ header file trying to include a.h */
extern "C" {
#include "a.h"}

/* -------- end b.cpp */

I am compiling using this command:

%g++ -o b.o b.cpp

Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?
private is a C++ keyword, and you're building with a C++ compiler (the
extern "C" only affects the linkage, not the language syntax that is
permissible). It would not be any better if an identifier were named
"class", "template", or any of the other keywords that C++ has that C
does not. You need to modify the header, or you can't use it with C++
code.

Cheers! --M

Apr 11 '07 #3
jo***********@gmail.com wrote:
I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private". I've reproduced the problem
as follows:

/* -------- a.h - the C header file */
#ifndef TEST_H
#define TEST_H

struct s
{
void *private;
};

#endif
/* -------- end a.h */
/* -------- b.cpp - the C++ header file trying to include a.h */
extern "C" {
#include "a.h"
}
/* -------- end b.cpp */

I am compiling using this command:

%g++ -o b.o b.cpp

Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?
private is a C++ keyword. You cannot use it as a class member name.

Fei
Apr 11 '07 #4
On Apr 11, 3:25 pm, jois.de.vi...@gmail.com wrote:
I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private".
(...)
>
Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?
'extern "C"' does not mean "treat the following code as C even though
it is within a C++ program". It means that "make the following code
available to C code even though it is within C++ code".

- Anand

Apr 11 '07 #5
In article <11**********************@e65g2000hsc.googlegroups .com>,
<jo***********@gmail.comwrote:
>I'm trying to include a C header file from an external library in my C+
+ program but when I compile I get the following error:

error: expected unqualified-id before 'private'
error: abstract declarator 'void*' used as declaration
error: expected ';' before 'private'

It didn't take me long to figure out that the offending C header file
uses a variable with the name "private". I've reproduced the problem
as follows:

/* -------- a.h - the C header file */
#ifndef TEST_H
#define TEST_H

struct s
{
void *private;
};

#endif
/* -------- end a.h */
/* -------- b.cpp - the C++ header file trying to include a.h */
extern "C" {
#include "a.h"
}
/* -------- end b.cpp */

I am compiling using this command:

%g++ -o b.o b.cpp

Despite enclosing the inclusion of the header file with extern "C",
the problem persists. As far as I know, 'private' is not a C key word
(confirmed by the fact that it compiles with the C compiler).

What am I doing wrong here?
extern "C" does not mean that from that point the C++ compiler
acts as a C compiler. It's still C++. So while it's true that
C does not support a private keyword, C++ does, hence that
keyword still exists when compiling as C++. As it should.
Perhaps this will help in some way:

http://www.comeaucomputing.com/techtalk/#externc
--
Greg Comeau / 4.3.9 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Apr 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
3
by: modemer | last post by:
Hello, I got weird compiling message similar like following when I compiled my simple code on Sun 5.8 with CC WorkShop 6 update 2 C++ 5.3. CC -g -o myclass.o -c myclass.cpp CC -g -o main.o...
0
by: David W. Fenton | last post by:
Today I was working on a hideous old app that I created a long time ago that does a lot of showing/hiding/resizing of fields on one of the forms. I had used constants to store reference values for...
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
2
by: Rudy Ray Moore | last post by:
Hi guys, I just upgraded to "Visual Studio .net 2003 7.1 c++" from VS6. Some things I like (proper for loop variable scoping, for example), but some other things are troubling me. One...
1
by: Jim Heavey | last post by:
Hello, trying to round out my knowlege here about compiling. To date I have used VS.Net to do all my compiling "majically", but I want to understand how to do it on my own, should the need ever...
10
by: Christina N | last post by:
When compiling my ASP.Net application, VS puts the new DLL under the local cached directory 'VSWebCache' in stead of on the server. How can I make it save the DLL file on the server when compiling?...
2
by: Justin Naidl | last post by:
A group of friends and I are doing a RPG (role-playing game) maker for a school project. It occured to us, however, that if you want the user to be able to have almost complete control over the...
8
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the...
0
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help compiling code dynamically it may involve some reflection so if any one is any good in that field or compiling code this would be a great time to show me what you know. by the way my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.