Dh*********@gma il.com top-posted, but I've fixed that. He said:
v4vijayakumar wrote:
>Happened to see my old (last millennium) c code. Almost forgot that I
wrote it .
It is interesting. :-)
int sqrt(int no)
{
int t;
no = t * t;
return t;
}
Can u tell me what is interesting in this code ??
No, there isn't any regular comp.lang.c contributor called "u".
(Translation: abbreviating "you" to "u" marks you out as someone who can't
even spell "you" properly. Take the time to type "you" in full, in the
interests of clear communication and of not looking idiotic.)
Here are the principal points of interest:
1) function name choice invades implementation namespace, thus invoking
undefined behaviour;
2) function name choice gives a misleading impression of what the function
tries to do;
3) t's value is indeterminate, but the function still attempts to use t's
value regardless, thus invoking undefined behaviour;
4) a parameter is used solely for assigning a value to, and this value will
be lost at the same time that the parameter itself is lost, at the end of
this function;
5) an indeterminate value is returned from this function, thus invoking
undefined behaviour in any caller that evaluates it;
6) even if all those faults were fixed, the function would still need major
repair work (type choices, range validation, etc).
Summary: it was written by someone who didn't know C very well six or seven
years ago. Whether they have learned their lessons in the meantime, I
cannot say.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.