Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:40:08+00:00 2026-05-24T03:40:08+00:00

I looks like I may need to embark on some cross-platform project and part

  • 0

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.

  • 1 1 Answer
  • 4 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:40:08+00:00Added an answer on May 24, 2026 at 3:40 am

    Rules

    • Use UTF formats to store strings, not "code pages" or whatnot (UTF-16 is probably easier edit: I totally forgot about byte order issues; UTF-8 is probably the way to go).

    • Use null-terminated strings instead of counted strings, as these are the easiest to access from most languages. But be careful about buffer overflows.
      Update 6 years later: I recommended this API for interoperability reasons (since so many already use null-termination, and there are multiple ways to represent counted strings), not the best one from a best-design standpoint. Today I would probably say the former is less important and recommend using counted strings rather than null-terminated strings if you can do it.

    • Do not even try to use classes like std::string to pass around strings to/from the user. Even your own program can break after upgrading your compiler/libraries (since their implementation detail is just that: an implementation detail), let alone the fact that non-C++ programs will have trouble with it.
      Update 6 years later: This is strictly for language and ABI compatibility reasons with other languages, not general advice for C++ program development. If you’re doing C++ development, cross-platform or otherwise, use the STL! i.e. only follow this advice if you need to call your code from other languages.

    • Avoid allocating strings for the user unless it’s truly painful for the user otherwise. Instead, take in a buffer and fill it up with data. That way you don’t have to force the user to use a particular function to free the data. (This is also often a performance advantage as well, since it lets the user allocate small buffers on the stack. But if you do do that, provide your own function to free the data. You can’t assume that your malloc or new can be freed with their free or delete — they often can’t be.)

    Note:

    Just to clarify, "let the user allocate the buffer" and "use NULL-terminated strings" do not run against each other. You still need to get the buffer length from the user, but you include the NULL when you terminate the string. My point was not that you should make a function similar to scanf("%s"), which is obviously unusably dangerous — you still need the buffer length from the user. i.e. Do pretty much what Windows does in this regard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my project i need to use the jQuery Rule Plugin Its looks like
I'm trying to parse a log file that looks like this: %%%% 09-May-2009 04:10:29
The html structure looks like this <div id=parent> parent may contain text <div id=child1>
I have a string which may contain cell address, which is look like: A1,
In Python, I need a dictionary object which looks like: {'a': 10, 'b': 20,
I've an upcoming project where I will need to handle very large uploads from
Suppose I have a base form Main1 which may need to be altered slightly,
I need a ReadWriteLock that is NOT reentrant, because the lock may be released
I have a two tables (actually sets of tables) which may need to be
I have a table that looks like: Key Date ... Name ... Status ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.