[RFC] libstdc++/9817 or "passing C++ strings to C functions"
Martin Sebor
sebor@roguewave.com
Mon Feb 24 00:29:00 GMT 2003
Paolo Carlini wrote:
> Paolo Carlini wrote:
>
>> For concreteness, you will find attached a *very* rough and redundant
>> (please, be gentle ;) implementation of the idea. I'm still not sure
>> if this is allowed by the standard and if less costly solutions are
>> worthy (for instance calling the underlying strcoll more than one time
>> for each hunk).
>
>
> Sigh :(
>
> As written, this cannot possibly be correct: if one string happens to have
> the chosen char (e.g., '$') in exactly the same place where the other had
> '\0' before the preprocessing they end up comparing wrongly equal...
Right. A better (but still not 100% reliable) hack might be to
substitute '\1' for '\0' since there's no character less than
it other than '\0'. The hack will not be reliable in "languages"
where "x\1" collates before "x\0" (remember that collating
elements may consist of multiple characters). AFAIK, the only
way to do this reliably is by somehow getting access to the
collation tables (e.g., by creating your own by parsing the
locale definition files). This is an example of a C++ feature
that cannot be portably implemented on top of the C Standard
library.
Regards
Martin
More information about the Libstdc++
mailing list