From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,803df5f3f60558d5 X-Google-Attributes: gid103376,public From: bcf@swlpts1.ssd.ray.com (Felaco) Subject: Re: Uninitialized variables, Java example Date: 1996/07/24 Message-ID: #1/1 X-Deja-AN: 169922257 sender: news@ssd.ray.com (Administrator) x-nntp-posting-host: swlpts1.ssd.ray.com references: <31EEACDA.64880EEB@sage.inel.gov> organization: Raytheon Electronic Systems - Software Engineering Laboratory newsgroups: comp.lang.ada Date: 1996-07-24T00:00:00+00:00 List-Id: In article , arra@inmet.com (Arra Avakian) writes: >This message appears even though all dynamic paths to the use of foo do in >fact initialize the variable. For example, a switch statement without a >default initializes the variable in all branches, but the compiler knows that >if the default case occurs, the variable is not initialized. The programmer >"knows" that the default case can not occur, but the compiler forces the >programmer to initialize foo to get a successful compile, i.e. it will not >produce the class file without the "unnecessary" initialization. I recently did some work with a code checker on a large C program. The customer had analyzed the system and had concerns about the quality based on the large number of errors the code checker reported. Many of the errors were uninitialized variables. The example you gave was a common reason for the errors. It was a major hassle to track down the real programming errors from the errors that were really just lazy programming. In a language like C, the least you can do is put a comment saying /* this case will never happen, so I didn't bother programming for it */ >Some may view this as extreme, since the compiler can not know statically the >"truth", and forces a statically knowable work-around on the programmer. Is >this what some people want for Ada 0x? It seems to me to be a tradeoff between >efficiency (an unnecessary initialization to satisfy the compiler) and safety >(the compiler is then allowed to detect statically known cases of >uninitialized variables, i.e. true programming errors.) The programmer must >analyze the error message and determine whether it is a programming error to >be fixed, or a case where an "unnecessary" initialization is needed to quiet >the compiler. In Ada, the example you gave does not apply, since all values of a case statement must be covered anyway. I think an Ada compiler is in a better position to check that all variables are initialized than a C compiler (or a C derivative language such as Java). >From my experiences, I would rather have to satisfy a pedantic compiler than a pedantic customer armed with a code checking tool. ;-) I don't believe performance is seriously degraded by unnecessarily initializing variables. To allow even the possibility of an uninitialized variable being used is bad programming. >Arra Avakian >Intermetrics, Inc. >733 Concord Avenue >Cambridge, Massachusetts 02138 >USA >(617) 661-1840 >arra@inmet.com -- ------------------------------------------------------------------------------- Chris Felaco Phone: x4631 (Raynet 444, Local 842) Raytheon Company Email: bcf@ssd.ray.com -------------------------------------------------------------------------------