Article View: comp.std.c
Article #5378Query about typedef type-checking: the answer!
From: Steve Hosgood
Date: Mon, 03 Oct 1988 10:40
Date: Mon, 03 Oct 1988 10:40
41 lines
2701 bytes
2701 bytes
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@com.att.cbnews
chris@uucp.mimsy
karl@com.isc.ima.haddock
jagardner@uucp.watmath
henry@uucp.utzoo
bill@uucp.proxftl
am@uk.ac.cam.cl
jpn@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@uk.ac.swan.pyr
Swansea SA2 8PP | UUCP: ..!ukc!cybaswan.UUCP!iiit-sh
----------------------------------------+-------------------------------------
My views are not necessarily those of my employers!
Technical Details
Message-ID:
<96@cybaswan.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!bionet!agate!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!reading!cf-cm!cybaswan!iiit-shShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!bionet!agate!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!reading!cf-cm!cybaswan!iiit-sh From: iiit-sh@cybaswan.UUCP (Steve Hosgood) Newsgroups: comp.std.c Subject: Query about typedef type-checking: the answer! Keywords: warnings, ANSI, typedef, type checking Message-ID: <96@cybaswan.UUCP> Date: 3 Oct 88 10:40:59 GMT Organization: Institute for Industrial Information Technology Lines: 41