Optimization considered harmful

Doug Gwyn gwyn at smoke.brl.mil
Wed Nov 7 21:18:36 AEST 1990


In article <1990Oct31.014132.2400 at agate.berkeley.edu> bks at alfa.berkeley.edu (Brad Sherman) writes:
>I have included a program below which is broken by the Microsoft 6.0
>compiler on MSDOS.   While this is no great surprise, ...

>	if ((s_array = (STRING **)malloc(100 * sizeof(STRING))) == NULL) {
------------------------------------------------------^^^^^^
Should be STRING *.

>		if ((s_array[i]->s = (char *)malloc(10)) == NULL) {
----------------------------------------------------^^
Should be 10 * sizeof(char), in order to get the right argument type.

>}
Should be preceded by return 0;.

>Now, which of the following lessons should be drawn from this event:
>	1) Don't use "register."
>	2) Don't use optimizers (or in this case be sure to disable optimizer).
>	3) Don't use "improved" Microsoft products.

	0) Make sure the code is supposed to work before looking elsewhere.
Assuming that fixing the code doesn't solve the problem, then
	4) Report the bug to the vendor and devise a work-around.

I can't recommend any of alternatives 1-3.



More information about the Comp.lang.c mailing list