Query about typedef type-checking: the answer!

Steve Hosgood iiit-sh at cybaswan.UUCP
Mon Oct 3 20:40:59 AEST 1988


Many thanks to the following who replied to my query about whether or not you
could expect a warning if you mix 'genuine' types and 'typedef-ed' types
in expressions:

	lvc at com.att.cbnews
	chris at uucp.mimsy
	karl at com.isc.ima.haddock
	jagardner at uucp.watmath
	henry at uucp.utzoo
	bill at uucp.proxftl
	am at uk.ac.cam.cl
	jpn at com.genrad

The unanimous (sp?) answer was that yes, you can mix a type and a typedef
perfectly freely if the types end up being the same thing, as a typedef merely
creates an alias for a type, and doesn't create a 'new' type as such. Doing this
will not cause any comment from an ANSI compiler, though an individual vendor
would be free to provide a warning message if he wanted to.

This answers my query very fully. My thanks to all those who replied.
The reason I asked was that I recently spent *ages* trying to find a bug in some
code where I use a 'long' to hold a fixed-point 'real' number. To tidy things
up, I used typedef to give me a type called 'fixed_t' that was really a 'long'.
The bug happened when I passed one of these items to a subroutine that wanted
a genuine 'long' as a parameter. The compiler didn't complain, but I ended up
with scrambled results!

What I really need then, is a feature like typedef, but which actually creates
a *new* type, not just an alias. I will not be requesting such a feature! I
know full well that such a 'feature' would need the ability to create functions
that are infix operators for these 'new' types etc, etc. In fact, I seem to
remember that all that got discussed a month or two back in this group.

-----------------------------------------------+------------------------------
Steve Hosgood BSc,                             | Phone (+44) 792 295213
Image Processing and Systems Engineer,         | Fax (+44) 792 295532
Institute for Industrial Information Techology,| Telex 48149
Innovation Centre, University of Wales, +------+ JANET: iiit-sh at uk.ac.swan.pyr
Swansea SA2 8PP                         | UUCP: ..!ukc!cybaswan.UUCP!iiit-sh
----------------------------------------+-------------------------------------
            My views are not necessarily those of my employers!



More information about the Comp.std.c mailing list