iiit-sh@cybaswan.UUCP (Steve Hosgood) (10/03/88)
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!diamond@csl.sony.JUNET (Norman Diamond) (10/11/88)
In article <96@cybaswan.UUCP>, iiit-sh@cybaswan.UUCP (Steve Hosgood) writes: > What I really need then, is a feature like typedef, but which actually creates > a *new* type, not just an alias. If you need it badly enough, put it in a struct. > 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. If you need it badly enough, there are half a dozen other popular programming languages that already do this for you. -- ------------------------------------------------------------------------------- The above opinions are my own. | Norman Diamond If they're also your opinions, | Sony Computer Science Laboratory, Inc. you're infringing my copyright. | diamond%csl.sony.jp@relay.cs.net