Article View: comp.lang.misc
Article #6604Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing)
From: Peter da Silva
Date: Fri, 12 Jan 1990 18:58
Date: Fri, 12 Jan 1990 18:58
34 lines
1587 bytes
1587 bytes
> This last sentence bothers me. It would be quite simple to implement
> a C operator such as "(typeof) x" that returns some representation of
> the type of the variable x.
I think this would be a worthwhile innovation, and one that's as easy
to implement as sizeof. It wouldn't return a value, but would be used
anywhere a type could be used.
I realise this isn't quite what's meant here. An operator to return
some indication of the type of an object would be useful, but I'm not
sure what it'd return. A small integer? A structure? A pointer to a
structure? The "type" of a C object can be very complex... what would
it return for:
struct {
union uabc {
struct {
int a;
int b;
} ab;
long c;
} abc;
union uabc *d;
struct stat buf;
} x;
But a typeof operator... wouldn't that be something...
#define SWAP(a,b) {typeof a tmp; tmp=a; a=b; b=tmp}
--
_--_|\ Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>.
/ \
\_.--._/ Xenix Support -- it's not just a job, it's an adventure!
v "Have you hugged your wolf today?" `-_-'
Technical Details
Message-ID:
<-K016ODxds13@ficc.uu.net>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!texbell!ficc!peterReferences:
<16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!texbell!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.lang.misc,comp.lang.c Subject: Typeof operator in C (Re: An Interesting View of "Strong" Vs. "Weak" Typing) Message-ID: <-K016ODxds13@ficc.uu.net> Date: 12 Jan 90 18:58:35 GMT References: <16678@megaron.cs.arizona.edu> <7106@tank.uchicago.edu> Reply-To: peter@ficc.uu.net (Peter da Silva) Followup-To: comp.lang.c Organization: Xenix Support, FICC Lines: 29