Search code examples
programming-languages

Language choice for a Unicode library: C or C++?


I'm writing a light Unicode library, but I'm stuck as to whether to write it for C, or C++? C++ has the benefit of operator overloads and better class handling, but many programs are written in plain C and it would seem nice to be compatible with C. How should I decide what language to write this for?

By the way, I know that there are many of these libraries around; I'm writing the library merely as an exercise, though I'll probably use it in my programs.


Solution

  • Easy - write it in C and have C++ wrappers. This makes both the C and C++ consumers happy, and if written correctly there's little overhead in wrapping C with C++. Be sure to follow sane models for re-entrant code - for example, having init and destroy functions handling struct pointers in C would correspond to constructors and destructors of a class in C++, where the struct pointer corresponds to the this pointer.