Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!nuchat!sugar!peter
From: peter@sugar.UUCP (Peter da Silva)
Newsgroups: comp.lang.c
Subject: Re: How to discriminate the structures?
Message-ID: <1226@sugar.UUCP>
Date: Sat, 5-Dec-87 09:17:16 EST
Article-I.D.: sugar.1226
Posted: Sat Dec  5 09:17:16 1987
Date-Received: Fri, 11-Dec-87 05:33:51 EST
References: <420@slb-sdr.UUCP>
Organization: Sugar Land UNIX - Houston, TX
Lines: 39
Keywords: structure, typeof()
Summary: You lose, I'm afraid...

In article <420@slb-sdr.UUCP>, saito@slb-sdr.UUCP (Naoki Saito) writes:
> foo(point)
> caddr_t *point;
> {
>   if (typeof(*point) == POINT)
>     { do something...}
>   else if (typeof(*point) == POINTR)
>     { do something...}
> }

Alas, but typeof(*point) (if there was such an operation) would be (caddr_t *).

Do this:

typedef struct {
	enum { POINT, POINTR } TYPE;
	union {
		struct {
			float x, y;
		} point;
		struct {
			float r, theta;
		} pointr;
	} DATA;
} THING;

foo(thing)
THING thing;
{
	if(thing.TYPE == POINT)
		do something with thing.DATA.point
	else if(thing.TYPE == POINTR)
		do something with thing.DATA.pointr
}

You have to maintain TYPE yourself.
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.