Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Optimization considered harmful Message-ID: <14372@smoke.brl.mil> Date: 7 Nov 90 10:18:36 GMT References: <1990Oct31.014132.2400@agate.berkeley.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 25 In article <1990Oct31.014132.2400@agate.berkeley.edu> bks@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.