Hi,
I am working on a Tcl wrapper for a library written in C. It must run on Windows, Linux, and macOS. My last experience in C development was a good
30 years ago, but with AI, I already have the wrapper running on Windows
and Linux.
The library uses wchar_t for strings. So I need to convert between these
and
Tcl UTF-8 strings. The AI systems can generate me appropriate functions
that
(should) run on all three platforms.
However, I wondered whether the Tcl C API already has appropriate
conversion
functions that work on all platforms. The problem is unlikely to be new.
But I couldn't find anything.
Have I overlooked something, or do I actually have to implement my own conversion functions?
Torsten
Am 28.11.2025 um 15:41 schrieb Torsten:
Hi,
I am working on a Tcl wrapper for a library written in C. It must run on
Windows, Linux, and macOS. My last experience in C development was a good
30 years ago, but with AI, I already have the wrapper running on Windows
and Linux.
The library uses wchar_t for strings. So I need to convert between these and >> Tcl UTF-8 strings. The AI systems can generate me appropriate functions that >> (should) run on all three platforms.
However, I wondered whether the Tcl C API already has appropriate conversion >> functions that work on all platforms. The problem is unlikely to be new.
But I couldn't find anything.
Have I overlooked something, or do I actually have to implement my own
conversion functions?
Torsten
Yes, of cause, everything is there ;-).
Is it TCL 9?
Remark, that TCL 8.6 uses internally CESU-16, what is your format
In Tcl 9:
str=Tcl_GetStringFromObject(Obj,&size);
Tcl_UtfToWCharDString(str, size, dsPtr)
See also the migration wiki, which gives more options.
Harald
...
Thank you for the answer. I'm still on 8.6.
So the options are to stay with 8.6 with self-written functions or
switch to 9.
-------- Original-Nachricht --------
Am 28.11.2025 um 15:41 schrieb Torsten:
Hi,
I am working on a Tcl wrapper for a library written in C. It must run on >>> Windows, Linux, and macOS. My last experience in C development was a
good
30 years ago, but with AI, I already have the wrapper running on Windows >>> and Linux.
The library uses wchar_t for strings. So I need to convert between
these and
Tcl UTF-8 strings. The AI systems can generate me appropriate
functions that
(should) run on all three platforms.
However, I wondered whether the Tcl C API already has appropriate
conversion
functions that work on all platforms. The problem is unlikely to be new. >>> But I couldn't find anything.
Have I overlooked something, or do I actually have to implement my own
conversion functions?
Torsten
Yes, of cause, everything is there ;-).
Is it TCL 9?
Remark, that TCL 8.6 uses internally CESU-16, what is your format
In Tcl 9:
str=Tcl_GetStringFromObject(Obj,&size);
Tcl_UtfToWCharDString(str, size, dsPtr)
See also the migration wiki, which gives more options.
Harald
Thank you for the answer. I'm still on 8.6.
So the options are to stay with 8.6 with self-written functions or
switch to 9.
Torsten
Torsten,
Remark that in tcl8.6, there are special functions for Windows to do that. But you are not on
Windows, right ?
But as long as you don't encode any NULL-Bytes, you may just use native TCL string encoding.
And as magic Christian pointed out, Non BMP characters are there using surrogates.
Take care,
Harald
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,089 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 153:53:57 |
| Calls: | 13,921 |
| Calls today: | 2 |
| Files: | 187,021 |
| D/L today: |
3,760 files (944M bytes) |
| Messages: | 2,457,163 |