#include <string.h>
void testok(void) reentrant { char buff[20];
buff[0]=1;
strcpy(buff,"hello");
//ok: buff = "hello"
}
void testfail(void) reentrant { char buff[20];
buff[0]=1; buff[2]=2;
//fail: buff = "ello"
void main(void) { testok(); testfail(); }
that doesn't mean that the code of strcpy is really the one in the library. it only says the proto type.
That would be true for non-standard library functions. But C Standard Library functions are different: once you've included their respective Standard Header, any attempt at overwriting their implementation would cause undefined behaviour, so all bets would be off anyway.
The only thing your two functions might do is consume time. And consumed time isn't really something the compiler needs to care about. Which is also why software-only busy loops are normally so bad.
I do not think you are right. the header file only has the prototype. not the implementation. lots of compiler have the source to libraries and you can change. they can be changed. you probably thinking of intrinsic.
they can be changed.
And any change that makes the function called strcpy() behave differently from the C Standard's requirement causes undefined behaviour.
you probably thinking of intrinsic.
No.
A failure of this would be far more convincing
#include <stdio.h> #include <string.h> void testok(void) reentrant { char buff[20]; buff[0]=1; strcpy(buff,"hello"); puts(buff); } void testfail(void) reentrant { char buff[20]; buff[0]=1; buff[2]=2; strcpy(buff,"hello"); puts(buff); } void main(void) { testok(); testfail(); }
no. it just not same as what you call standard. in the real world if you define the function it is not undefined behaviour. of course it assumes you KNOW how to write a proper function. you probably dont. LOL.
It is undefined behaviour if you include the support for CRTL and then perform something different than the CRTL function as described in the standard.
no. it just not same as what you call standard.
You seem to be beyond learning something new, but I'll drop you a few hints anyway.
*) It's not what I call standard, it is the Standard. There's a reason I spell it like that. *) You're incorrect in believing that you would get to decide what is undefined behaviour.
you probably dont. LOL. You really have no idea.
Lol. Don't get upset little man. I know more than you think I think.