How to put C header in C ++ namespace?

I created a C header for the C ++ static library foo.h, which looks like this:

#ifndef __FOO_H__
#define __FOO_H__

const size_t SOME_CONST = 22;

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

unsigned long foo();
...
void bar();

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __FOO_H__ */

I wanted to put it in some namespace in a different header cfoo. I wrote this:

#ifndef __CFOO__
#define __CFOO__

namespace foo {
#include "foo.h"
}

#endif /* __CFOO__ */

GCC shows no errors, and as I test everything looks fine, but I'm still not sure if this is the correct way to create this namespace. Can anyone confirm that this is a good way to do this, or maybe there are some suggestions to make it better?

+4
source share

No one has answered this question yet.

See similar questions:

:

4247
++
3076
++?
2873
?
2416
, ?

Source: https://habr.com/ru/post/1615117/


All Articles