From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,cf4ba3d07912d446 X-Google-Attributes: gid1094ba,public X-Google-Thread: 1164f8,cf4ba3d07912d446 X-Google-Attributes: gid1164f8,public From: "Kevin G. Rhoads" Subject: SUMMARY: Code errors which can masquerade as compiler bugs Re: Mysterious data corruption in Fortran with -automatic Date: 1998/06/06 Message-ID: <01bd91bc$ac64ac80$LocalHost@stupidwin95>#1/1 X-Deja-AN: 360278219 References: Newsgroups: comp.sys.dec,comp.lang.fortran Summary: Compiler bugs are real, but should be one of the *last* things to check. Most language specific comments were directed to Fortran and C. Programmer errors which a) manifest or disappear depending upon compiler, settings, machine, data b) can be misinterpreted as compiler bugs include: 1) Uninitialized variables 2) Aliasing - can occur in any language by passing the same variable by reference to two or more parameters in the argument list of a function or subroutine -- in addition to the more commonly noted pointer aliasing -- in Fortran, we can add passing a variable by reference to a parameter when it is accessed by COMMON block as well 3) assumptions about persistence/lifetime -- particularly local variables: are they static or automatic -- in Fortran use SAVE as needed 4) assumptions about precedence and execution order in expressions -- in Fortran use parentheses (in C add also the comma operator) -- and C programmers working in other languages particularly beware that other languages DO NOT guarantee short-circuit evaluation nor strict left-to-right evaluation of Boolean/Logical expressions as does the C standard 5) assumptions about memory layout (e.g., byte order), machine level format of types (e.g., ones-complement, twos-complement or sign-magnitude) and packing -- these assumptions also make code non-portable and are not limited to memory, Fortran unformatted files are another place to check for this 6) incorrect subroutine/function calls i) mismatched arguments - wrong size or type (e.g., passing a 4 byte integer to a parameter expecting a two byte integer will work on Intel boxes and blow up on any big-endian machine) ii) incorrect number of arguments (C, many other languages will crash obviously) 7) array bounds overruns 8) string length overruns 9) insufficient stack --------------------------------------- SPECULATION: I also note that the respondents *seemed* to divide into two camps: one group felt compiler bugs were real, but quite rare another group seemed to feel compiler bugs were not uncommon Perhaps this reflects platforms: workstation vs. wintel Perhaps this is just randomness, a reflection of the small number of total respondents. Investigating this seems destined to create more flame than aught else. If someone with an asbestos beany-copter wishes to ask this question, go right ahead. I am not touching it. -- Kevin G. Rhoads, Ph.D. T_Rhoads@NO_SPAM.Classic.MSN.COM KRhoads@NO_SPAM.CmpNetMail.com