What is current best practice around use of strings in cross-platform C and C++ APIs?

Viewed 711

I looks like I may need to embark on some cross-platform project and part of it will have to be done in C or C++ (not decided yet hence the question is about them both). I will be dealing mostly with the text-based stuff and strings in general.

That C/C++ will have an API callable from the higher-level platform-dependent code.

My question is: what type(s) is it advisable to use to work with strings, in particular when declaring public interfaces? Are there any recommended standard techniques? Are there things to avoid?

I have little experience of writing C or C++ code, and even that was on Windows, so nothing like cross-platform here at all. So what I'm really looking for is for something to get me on the right way and avoid doing stupid things which are bound to cause a lot of pain.


Edit 1: To give a bit more context about the intended use. The API will be consumed by:

  • Objective C on iPhone/iPad/Mac via NSString and friends. The API can be statically linked, so no need to worry about .so .dll issues here.

  • Java via JNI on Android and other Java platforms

  • .NET via p/invoke from the managed C# code or natively statically linked if using C++/CLI.

  • There are some thoughts about using lua somehow/somewhere in this context. Don't know if this has any bearing on anything though.

4 Answers
Related