NULL as a string terminator

Chris Preston cbp at icc.com
Tue Aug 21 15:42:58 AEST 1990


>From article <3585 at goanna.cs.rmit.oz.au>, by ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe):
> In article <1990Aug20.000227.12867 at icc.com>, cbp at icc.com (Chris Preston) writes:
> (quoting a quote)
>> >Other cases occur where someone makes #defines for error strings
>> >that are used only once:
> 
>> >#define	FOO_BAR_ERROR	"foo bar error"
>> >#define UNDEF_BAZ_ERR	"undef baz err"
>> >
>> >I cringe when I come across code like this.  Needlessly removing objects
>> >a level is distracting and gains nothing.
> 
> and then defends this, where there are conditional definitions.
> He suggests
>>   #if MSDOS
>>   #define DATACOM_NOT_INIT "Execute datacomm.exe and restart the program"
>>   #elif  SYSV
>>   #define DATACOM_NOT_INIT "Contact you system administrator for datacomm startup"

and I said etc, etc.

> as an example of a Good Thing.  I cringe when I see code like this too.

  No, an example of separating abstraction through the use of lables.

> For why?  Internationalisation, _that's_ for why.

  Hm, now we go to a different level.  Probably a good point.

>>   It also impacts on the reusability of code.  Pay me now or pay me later.
> 
> Considering the large negative impact on internationalisation of having
> fixed strings in the program, may we _bill_ him, I wonder?

  We is out of context, and no, you may not.

> 
> A very simple way of making a "resource file" in UNIX is this:

  deleted.

> 
> The bottom line is that you can just make a whole bunch of files
> 	resource.uk
> 	resource.us
> 	resource.fr
> 	resource.dk
> and so on, then
> 	awk -f resource.awk resource.$LANG >resource.h
> and re'make'ing your program will let you adapt to a different language.
> 
> (I used awk here to keep this posting short.  It would be better to make
> the header file with a C program so that you could use ftell() to get
> exactly the right values to give to fseek().)

  Sure, and if one does this in System V one could just push a streams module 
  on top of the line discipline and let all applications work in the chosen 
  language.  Quick, neat and available.  But we digress into issues of O/S
  rapidly here.

  At this point someone politely suggests that the newsgroup and its
  O/S independence is worth considering.  
  
 In that spirit, I would like to return to the actual issue (as noted in
 the subject line, though I was guilty of diverging from it ).
 I have been thinking more on the EOS issue, and since 
 it would break lots of things were someone to do this in other than
 special cases (like, breaking all string functions is rude, don't you think?), 
 means that I was wrong in suggestion labeling '\0' in anything other than
 itself is a good idea.  
 
 Retraction is hereby submitted.
  
 Better not to touch that which is so basic to the language itself.  There is no
 clearly important benefit in allowing for a change of such an unlikely nature.

 Basta, finito.

cbp
cbp at icc.com
---------
That is twice in one day --al, don't let it get to you.
---------
Of course, these are opinions.



More information about the Comp.lang.c mailing list