Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!batcomputer!itsgw!steinmetz!uunet!vsi!sullivan
From: sullivan@vsi.UUCP (Michael T Sullivan)
Newsgroups: comp.std.c
Subject: Re: switch (expression)
Summary: Casting ptr to int
Message-ID: <755@vsi.UUCP>
Date: 13 Jul 88 15:03:03 GMT
References: <1988Jul12.105547.13268@light.uucp>
Organization: V-Systems, Inc. -- Santa Ana, CA
Lines: 29

In article <1988Jul12.105547.13268@light.uucp>, bvs@light.uucp (Bakul Shah) writes:
> dpANS says the expression in ``_s_w_i_t_c_h (expression)''
> must be an integer valued expression.  Any chance of
> getting this changed ``must be an integer or ptr valued
> expression''?  The current restriction forces one to use
> the messier and longer sequence of ``if..then..else if
> ...'' for pointers...
> 
> Note that the switch stmt can be used by casting the ptr
> to a long or an int, but I don't know if this is safe on
> all architectures -- (casts) should be avoided where
> possible.

I don't know about casting should be avoided.  I'm looking at shmop(2) manual
page for our 3B2 (shared memory operation) and it says:

	"Shmat {which is a char* function -mts} returns the data segment
	start address of the attached shared memory segment...

	Otherwise, a value of -1 is returned and errno is set to indicate
	the error."

Somebody at AT&T must think casting a pointer to an int (or a long) isn't
such a bad idea, unless I'm missing something (it has been known to happen).

-- 
Michael Sullivan			{uunet|attmail}!vsi!sullivan
V-Systems, Inc.  Santa Ana, CA		sullivan@vsi.com
ons, workstations, workstations, workstations, workstations, workstations, work