1000 lines of C a week?

der Mouse mouse at mcgill-vision.UUCP
Tue Jun 27 19:53:54 AEST 1989


In article <19436 at cup.portal.com>, Tim_CDC_Roberts at cup.portal.com writes:
> In <18783 at vax5.CIT.CORNELL.EDU>, sc2y at vax5.cit.cornell.edu asks with
>   tongue in cheek:
>>> A project needs a person with a proven capability of generating a
>>> thousand lines of debugged C a week.

>> Okay, how about this?
>>   /* compute square root of a number if less than 1000 */
>>   float comp_sqrt(x) int x; {
>>    if (x  == 1)
>>      return (sqrt(x));
>>     ....

> Since you didn't declare "double sqrt (double)",

If we're being picky, he also didn't say the code he exhibited was the
entire file: it could have been just one routine extracted from a file
which quite possibly had a line "#include <math.h>" above the sample.

> and you are passing an int to a function expecting a double, and
> returning a double for a function that is supposed to return a float,
> this function will fail on any machine where sizeof(int) !=
> sizeof(double) or sizeof(float) != sizeof(double).

Actually (under the assumptions you made, ie, no declarations), it
requires more than just that int and double have the same size - it
also requires that for all values 1 to 999, the bit patterns are
identical and are passed to sqrt() in the same way.  (I expect this
excludes all existing C compilers.  I certainly *hope* it does!)

The "returning a double when supposed to return a float" is specious:
return values have always been cast to the proper type for the
function, even in Classic C.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list