[clug] [OT] Null-terminated strings: expensive mistake or not

Sam Couter sam at couter.id.au
Thu Aug 4 03:54:22 MDT 2011


Robert Edwards <bob at cs.anu.edu.au> wrote:
> I might be splitting hairs here, but if you don't like \0-terminated
> strings, you can write your own functions in C that use a different
> representation of a string and the only way the compiler would not
> be helpful is in dealing with initialising string constants - you would
> need to write a macro to do this instead.
> 
> Or am I wrong on this one?

You are absolutely correct. I can't be the only C programmer to write my
own half-baked string handling library.

Here's a much better, more widely used example of one:

http://developer.gnome.org/glib/stable/glib-Strings.html

The problem comes when you need to interface with other libraries that
use the NUL-terminated convention.
-- 
Sam Couter         |  mailto:sam at couter.id.au
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/linux/attachments/20110804/09f31cb7/attachment.pgp>


More information about the linux mailing list