Le 07-10-2005, pete <> a écrit*:
> Marc Boyer wrote:
>
>> Here is a well defined program:
>>
>> #include <stdio.h>
>> #include <string.h>
>>
>> int main(){
>> void* p= &p;
>> if ( strlen("abc") < sizeof(p) ){
>> memcpy(p, "abc", strlen("abc")+1 );
>> puts( (char*) p );
>
> It's not defined and these issues have
> already been gone over in this thread.
>
> p is an indeterminate pointer after the memcpy call.
Yes, sorry. I ve not posted the right version.
> Accessing the value of p at that point,
> as the cast operator does, is undefined.
Of course.
> #include <stdio.h>
> #include <string.h>
>
> #include <stdio.h>
> #include <string.h>
>
> int main(void)
> {
> void *p = &p;
>
> if (strlen("abc") < sizeof(p)) {
> strcpy(p, "abc");
> puts((char *)&p);
> } else {
> puts("Pointers too small");
> }
> return 0;
> }
Yes
--
À vélo, prendre une rue à contre-sens est moins dangeureux
que prendre un boulevard dans le sens légal. À qui la faute ?
|