Date: Mon, 26 Aug 1996 10:12:51 +0200 (SAT) From: Robert Nordier <rnordier@iafrica.com> To: hoek@freenet.hamilton.on.ca Cc: questions@FreeBSD.org Subject: Re: Programming Question Message-ID: <199608260812.KAA02909@eac.iafrica.com> In-Reply-To: <199608251921.PAA01735@james.freenet.hamilton.on.ca> from "hoek@freenet.hamilton.on.ca" at Aug 25, 96 03:21:24 pm
next in thread | previous in thread | raw e-mail | index | archive | help
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 <AT> = <int> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608260812.KAA02909>
