Referencing C header file that has new as param?

A

andrejohn.mas

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
 
K

Kai-Uwe Bux

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
 
R

red floyd

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
 
A

andrejohn.mas

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 :
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top