Xref: utzoo comp.arch:2979 comp.lang.c:5735 Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.arch,comp.lang.c Subject: Re: C machine Message-ID: <9907@mimsy.UUCP> Date: 20 Dec 87 21:52:29 GMT References: <261@ivory.SanDiego.NCR.COM> <164@sdeggo.UUCP> <3078@phri.UUCP> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 39 [I am moving this to comp.lang.c] >In article <164@sdeggo.UUCP> dave@sdeggo.UUCP (David L. Smith) writes: >>Besides, there's nothing that says you can't write a string package which >>has the string preceeded by the length. It is not hard, but it is annoying: In article <3078@phri.UUCP>, roy@phri.UUCP (Roy Smith) writes: >... the problem is that the C compiler only supports null-terminated >string constants (of the form "I am a string"). Either you have to >learn to live without string constants, or put up with having to >initialize everything with 'cvt_null2count ("string constant")' at run time. The following works: typedef struct string { int s_len; char *s_str; } string; #define STRING(x) { sizeof(x) - 1, x } string foo = STRING("this is a counted string"); Unfortunately, some compilers (including 4BSD PCC) then generate the string twice in data space, and the `xstr' program only makes it worse. In addition, since automatic aggregate initialisers are not permitted, and there are no aggregate constants, automatic data must be initialised with something like this: f() { static string s_init = STRING("initial value for s"); string s = s_init; ... (I believe the dpANS allows automatic aggregate initialisers.) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris