[cfe-dev] add namespaces to C (in my local clang) OR "tag" a couple of functions

Jonas Gefele llvm.org at schrieb.de
Fri Oct 21 01:42:50 PDT 2011


Hi,

thank you for your reply. Personally, I would prefer switching to C++ too.
But it is unfortunately not possible :(

I have been a little imprecise when I said "compability
with real world C does not matter in my case". I meant this on a
naming/linkage level (as we can handle this in our linker).

We have a big C code base and need source level compability (to the
greatest possible extent). Introducing two new keywords "namespace" and
"using" would not hurt much. But needing to fix tons of "void-pointer
assignments" like:

   char* x = malloc(100);
   char* y = malloc(100);
   char* z = malloc(100);

would hurt a lot.


Cheers,
Jonas

> On Fri, Oct 21, 2011 at 12:33 AM, Jonas Gefele <llvm.org at schrieb.de>
> wrote:
>> (In my local clang copy) I would like to add namespace support to C. I
>> want to use it to "tag" a couple of functions like this:
>>
>> namespace tag1 {
>
>> (In my local clang copy) I need the ability to "tag" a bunch of C/C++
>> functions/globals with some "name". Something like:
>
> Would it work to just compile your C sources with a C++ compiler?
>
> /* Foo.c
>  */
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> #include "Foo.h"  /* These function names will not be mangled */
>
> #ifdef __cplusplus
> }
> #endif
>
> #ifdef __cplusplus
> namespace tag1{
> #endif
>
> void foo( int bar )
> {
>   getDownAndBoogie();
>
>   return;
> }
>
> #ifdef __cplusplus
> } /* namespace tag1 */
> #endif
>
> Some creative macro definitions could make that look less ugly.
>
>
>
>
> --
> Don Quixote de la Mancha
> Dulcinea Technologies Corporation
> Software of Elegance and Beauty
> http://www.dulcineatech.com
> quixote at dulcineatech.com
>




More information about the cfe-dev mailing list