Re: realloc
Michael Knaup wrote:[color=blue]
>[color=green]
>> However, in general would the restrict qualifier afford
>> protection? I am envisioning something like:
>>
>> char *s2, s1[SIZE] = "some nonsense";
>>
>> s2 = strchr(s1, 'n');
>> ... obscurative code ...
>> if ((strlen(s1) + strlen(s2)) < SIZE) cat(s1, s2)[/color]
>
> The function cat concatenatiats two "heap" strings allocated by
> malloc or realloc. You cannot usage cat with an static array as
> you did. So there is no real need for an size information as long
> as s1 and s2 are (0 terminatet) C strings.[/color]
I gave the prototype for the cat I was discussing as:
char *cat(restrict char *dst, const char *src);
which in no way restricts the strings to be in memory allocated by
malloc etc. There is no way, in standard C, to so restrict
parameters, and any code that requires it is a bomb waiting to
explode. It is so silly a practice that I never conceived anyone
would write code requiring it.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Michael Knaup wrote:[color=blue]
>[color=green]
>> However, in general would the restrict qualifier afford
>> protection? I am envisioning something like:
>>
>> char *s2, s1[SIZE] = "some nonsense";
>>
>> s2 = strchr(s1, 'n');
>> ... obscurative code ...
>> if ((strlen(s1) + strlen(s2)) < SIZE) cat(s1, s2)[/color]
>
> The function cat concatenatiats two "heap" strings allocated by
> malloc or realloc. You cannot usage cat with an static array as
> you did. So there is no real need for an size information as long
> as s1 and s2 are (0 terminatet) C strings.[/color]
I gave the prototype for the cat I was discussing as:
char *cat(restrict char *dst, const char *src);
which in no way restricts the strings to be in memory allocated by
malloc etc. There is no way, in standard C, to so restrict
parameters, and any code that requires it is a bomb waiting to
explode. It is so silly a practice that I never conceived anyone
would write code requiring it.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Comment