2 is wrong, while 1 and 3 are not so right

blaise (blaise)
syntaxly , 2 is wrong, because it try to return memory on the stack, when v() is finished the the memory on stack is released. the returned pointer ref to invalid memory.
1 and 3 are exactly the same except in debug build 1 will alloc one pointer on stack, in optimized mode, these 2 function will all probably return a constant address,semanticly, 1&3 are all wrong. The string "result of function v()" is allocated by compiler in Initialized data segement, but, notice, logically, it should be constant,although u can modify it.
const char^ v()
return "result of function v()";
will be the best way
2001-5-15 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: which one is right?

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论