This is the mail archive of the gcc@gcc.gnu.org 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 <Pine.LNX.4.10.9911061947330.20754-100000@se232.math.indiana.edu> 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
(see http://www.sds.lcs.mit.edu//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]