Am Freitag, 28. November 2003 17:39 schrieb ged.suse@ntlworld.com:
I'm currently rewriting many of the standard functions in C++. No i'm not wierd, i'm in the process of learning and figured this would be a good exercise.
Anyway, my strlen() function is bringing up a warning. Although I understand what the warning mean, I don't understand why it is a warning. Can someone please quickly point out the technicalities. The main point I sometimes trip up with is pointers and references (as I suspect most people learning C++ encounter)
int *MyStrlen(const char *source) { int i = 0; while (*source) { *source++; i++; } return &i; }
i is a var which is allocated in the context of this function. If you leave the function i is being deleted. But you return the adress of this space from your function this will crash... Better should be: int MyStrlen(....) { ... return i; } -- Andreas