By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

Referencing C header file that has new as param?

P: n/a
Hi,

I am writing a C++ program that needs to include a C header file. The
problem I am having is that a couple
of the functions have 'new' as parameter name:

int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen,
size_t *retval);
int userland_sysctl(struct proc *p, int *name, u_int namelen, void
*old,
size_t *oldlenp, int inkernel, void *new, size_t newlen,
size_t *retval);

Is there any way to include this file without my C++ compiler failing
because if this?

Andre

Sep 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
an***********@gmail.com wrote:
Hi,

I am writing a C++ program that needs to include a C header file. The
problem I am having is that a couple
of the functions have 'new' as parameter name:

int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen,
size_t *retval);
int userland_sysctl(struct proc *p, int *name, u_int namelen, void
*old,
size_t *oldlenp, int inkernel, void *new, size_t newlen,
size_t *retval);

Is there any way to include this file without my C++ compiler failing
because if this?
I think you're screwed short of the preprocessor. You might try:

#define new
#include "C_Header_file.h"
#undef new
Sep 20 '06 #2

P: n/a
an***********@gmail.com wrote:
Hi,

I am writing a C++ program that needs to include a C header file. The
problem I am having is that a couple
of the functions have 'new' as parameter name:

int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen,
size_t *retval);
int userland_sysctl(struct proc *p, int *name, u_int namelen, void
*old,
size_t *oldlenp, int inkernel, void *new, size_t newlen,
size_t *retval);

Is there any way to include this file without my C++ compiler failing
because if this?
I usually do not work with header files, so I have no idea about best
practices, but the following rather reckless method comes to mind: rewrite
the header -- the names of the parameters are not part of the function
signatures; thus, linking should still work. (Of course, your make tools
might bitch about file modification times, so you may want to keep the
original header. Also, you may not be allowed to do this for legal reasons
[creating a derivative work, etc.].)
Best

Kai-Uwe Bux
Sep 20 '06 #3

P: n/a
The only catch here is that the header is part of the FreeBSD header
file
"sys/sysctl.h":

http://fxr.watson.org/fxr/source/sys/sysctl.h

I could change it for myself, but if anyone else attempts to compile my
code then
they would have to modify the system headers. There must be a better
way.

Andre

Kai-Uwe Bux a écrit :
an***********@gmail.com wrote:
Hi,

I am writing a C++ program that needs to include a C header file. The
problem I am having is that a couple
of the functions have 'new' as parameter name:

int kernel_sysctl(struct proc *p, int *name, u_int namelen, void *old,
size_t *oldlenp, void *new, size_t newlen,
size_t *retval);
int userland_sysctl(struct proc *p, int *name, u_int namelen, void
*old,
size_t *oldlenp, int inkernel, void *new, size_t newlen,
size_t *retval);

Is there any way to include this file without my C++ compiler failing
because if this?

I usually do not work with header files, so I have no idea about best
practices, but the following rather reckless method comes to mind: rewrite
the header -- the names of the parameters are not part of the function
signatures; thus, linking should still work. (Of course, your make tools
might bitch about file modification times, so you may want to keep the
original header. Also, you may not be allowed to do this for legal reasons
[creating a derivative work, etc.].)
Best

Kai-Uwe Bux
Sep 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.