[net.lang.c] Question: initializers with casts?

jr@fortune.UUCP (John A. Rogers) (11/18/83)

Hi.  Yet another C question:  I'm interested in having one pointer point to
three different types of things.  I'd also like to be able to initialize
that pointer to any of those three.  My question is: Can I safely (and
portably) use casts in initializers?  (Being able to initialize the pointer
is important, as I need to let an applications programmer build a large table
which will be used by the routines I'm writing).

A simple version of what I want to do:
	short s;
	int *x = (int *) &s;
Note that this is a useless piece of code, but if it works, then what I want
to do should work.

The research I've done so far is:

	The "C Programming Language - Reference Manual" [Ritchie] is not clear.
	In section 15 ("Constant expressions"), it says that expressions using
	"&" can be used in initializers.  However, it doesn't mention casts.

	"The UNIX System", by Steve Bourne, says "expressions that initialize
	static or external variables must be constant expressions or
	expressions that reduce to the address of a previously declared
	variable possibly offset by some constant amount."  This would seem to
	say that what I want to do is legal.

	What I want to do works on my VAX (running V7 and 4.1? BSD) and on
	Fortune's 32:16 (running FOR:PRO 1.7, which is V7 and ?.? BSD).  It is
	also allowed by LINT on both systems.  Has Berkeley changed LINT to be
	more permissive than BTL's?  Or can I trust it?

If anyone can tell me (1) whether what I want to do is really portable, or
(2) is my example is not a good one, I'd appreciate it.  Thanks for your help!
-- 
John Rogers - CompuServe: 70140,213 - UUCP: fortune!jr - MCI Mail: jrhpp