This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: warning for typedef'ed type

In article <> you write:

>   I can't seem to find a way to force a warning if a function requires an
>argument of a typedef'ed type and is given an argument of the original
>type.  For example:

>typedef int scm;
>int f(scm a);

>void foo()
>   f(5);

This kind of stuff is very hard to warn about, as C is really not the
right language to achieve this level of control.

You might wish to look into C++. You can define an scm class that will
act as an int (conversion operator), but with no implicit constructor
from int.

As another venue, I spent quite some time playing with an advanced 
and versatile lint called lclint

It can enforce these kinds of restrictions  (typedef to enforce `abstract
types') and lots of other restrictions.

My personal experience was that, though useful, that program demands a huge
investment in time to add enough annotations to a program to make it clean
(let alone the modifications needed to unsafe constructs, and its inability
to cope with some Unix constructs like fork() properly), but your mileage
may vary.

[Take answers to private email, as this has little relevance to gcc itself].

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]