Mail Archives: djgpp/1998/09/09/22:15:34
wpp AT brinet DOT com escribió en mensaje <35e754f4 DOT 2457929 AT cnews DOT newsguy DOT com>...
>On Sat, 15 Aug 1998 13:15:28 -0300, Endlisnis <s257m AT unb DOT ca> wrote:
>
>>Cephaler wrote:
>>
>>> int main(void) {
>>> char *string1=(char *)malloc(80);
>>> char *string2;
>>> strcpy(string1,"foobar");
>>> string2 = string1;
>>> strcpy(string2,"raboof");
>>> printf("%s\n",string1);
>>> return(0);
>>> }
[...]
>>> 3) concerning strcpy...is there any special reason why I shouldn't just use
>>> string1 = "foobar" ?
>>
>> Not to my knowledge (except you can't 'free' that space).
In 'Cygnus' GCC, this definition is considered a 'non-const' pointer to a 'const'
bunch of bytes, i.e. you can point to it, but you can't modify this contents.
You can define 'char string1[]="foobar"' to avoid this behaviour.
DJGPP (with the aproppiate compiler options) warn this, but IIRC, 'Cygnus' not.
- Raw text -