From owner-freebsd-questions Mon Aug 26 01:17:18 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA26661 for questions-outgoing; Mon, 26 Aug 1996 01:17:18 -0700 (PDT) Received: from eac.iafrica.com (196-7-192-206.iafrica.com [196.7.192.206]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id BAA26656 for ; Mon, 26 Aug 1996 01:17:05 -0700 (PDT) Received: (from rnordier@localhost) by eac.iafrica.com (8.6.12/8.6.12) id KAA02909; Mon, 26 Aug 1996 10:12:52 +0200 From: Robert Nordier Message-Id: <199608260812.KAA02909@eac.iafrica.com> Subject: Re: Programming Question To: hoek@freenet.hamilton.on.ca Date: Mon, 26 Aug 1996 10:12:51 +0200 (SAT) Cc: questions@FreeBSD.org In-Reply-To: <199608251921.PAA01735@james.freenet.hamilton.on.ca> from "hoek@freenet.hamilton.on.ca" at Aug 25, 96 03:21:24 pm X-Mailer: ELM [version 2.4 PL24 ME8a] Content-Type: text Sender: owner-questions@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk hoek@freenet.hamilton.on.ca wrote: > It's been suggested before that this area is as good as any for asking > questions WRT to a certain aspect of one of the supplied compilers. > While I'm not certain I agree, here goes... > > Is there any way to make the C compiler use much stronger typing. For > example, I would really like it to warn about assigning signed variables > to unsigned ones. (I say this after spending way too much time hunting > down an unnecessary bug caused by the lack of such a warning). > > Heck, optimally, I sure wouldn't mind if it were to give me a warning when > assigning a variable of type TYPDEF to another identical variable declared > without the TYPDEF'd definition. > > For example, > > -- > signed int a; > unsigned int b; > > typedef int AT; > > AT aa; > int bb; > > void > main () { > a = b; > aa = bb; > } > -- > > would yield two warnings. > > I've tried just about every -W option listed, but none of them seem to > even come close. Is there anyway to massage the compiler into > complaining about these things? Note that 'typedef' doesn't create types, just synonyms for existing types. So the assignment = doesn't involve a type conflict in any sense. For automated nitpicking, I like 'lclint' (from the 'lcc' compiler people): | LCLint 2.0 --- 21 Mar 96 | | x.c:10,1: Function main declared to return void, should return int | The function main does not match the expected type. Use -maintype to | suppress message. | x.c: (in function main) | x.c:11,2: Assignment of unsigned int to int: a = b | Types are incompatible. Use -type to suppress message. | | Finished LCLint checking --- 2 code errors found -- Robert Nordier