strncat is insufficient

diamond@tkovoa diamond at tkou02.enet.dec.com
Thu Aug 16 10:31:39 AEST 1990


In article <12570054 at hpclscu.HP.COM> shankar at hpclscu.HP.COM (Shankar Unni) writes:
>Rahul: 
>> Most of the time I want to avoid string overflow by doing this:
>>    append str2 to str1, but cause at most n characters to be in str1.
[me too -- Diamond]
>Well, you could write a cheapo function that goes:
> strlimcat (char *s1, char *s2, int n) { strncat (s1, s2, (n - strlen(s1))); }
>which is exactly what strlimcat would have to do anyway..

Well, it's cheap in terms of development time, but not usually in execution
time.  You MIGHT have a super-optimizing compiler that has learned a trick
(newly authorized by ANSI) of remembering that strlen and strcat are special,
so it can remember that the length of s1 has been computed and does not have
to be computed a second time.  But you PROBABLY don't.

>Doug G:
>> There isn't much point in discussing it in this newsgroup.
>> We're not soliciting suggestions for changes to the standard.
>Ooohhh. Does that mean that C is frozen for eternity?

The standard suggests that a few features might be deprecated in the future.

>The "ultimate, greatest-ever language on earth"?

This opinion seems to be widely held though (except for some of the
adherents of C++).

>I think this is an appropriate place for suggestions for extensions to the
>language, too, in addition to questions about clarifications of items in
>the current standard...

I think so too.  But these suggestions are not being solicited.  Perhaps
we need yet another newsgroup, which certain users would not want to read.
comp.std.c.2001?
-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.



More information about the Comp.std.c mailing list