1 /*
2  * GSUnion.h
3  * File to set up a typedef for a union capable of containing various types.
4  * Copyright (C) 1999  Free Software Foundation, Inc.
5  *
6  * Author:	Richard Frith-Macdonald <richard@brainstorm.co.uk>
7  * Created:	Apr 1999
8  *
9  * This file is part of the GNUstep Base Library.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02111 USA. */
25 
26 /* Need Foundation/NSObjCRuntime.h for type declarations.
27  */
28 #import <Foundation/NSObjCRuntime.h>
29 
30 /* These are not defined in older Mac OS X systems */
31 #ifndef NSINTEGER_DEFINED
32 typedef intptr_t NSInteger;
33 typedef uintptr_t NSUInteger;
34 #define NSINTEGER_DEFINED 1
35 #endif
36 
37 /*
38  *	Definitions for bitmap mask of types of element in union.
39  */
40 #ifndef	GSUNION_OBJ
41 
42 #define	GSUNION_OBJ	0x0001
43 #define	GSUNION_CLS	0x0002
44 #define	GSUNION_SEL	0x0004
45 #define	GSUNION_PTR	0x0080
46 #define	GSUNION_NSINT	0x1000
47 
48 #define	GSUNION_ALL	0x1fff
49 
50 #endif	/* GSUNION_OBJ */
51 
52 
53 /*
54  * Produce a typedef for a union with name 'GSUNION' containing elements
55  * specified in the GSUNION_TYPES mask, and optionally with an extra
56  * element 'ext' of the type specified in GSUNION_EXTRA
57  *
58  * You can include this file more than once in order to produce different
59  * typedefs as long as you redefine 'GSUNION' before each inclusion.
60  */
61 
62 #if	defined(GSUNION) && defined(GSUNION_TYPES)
63 
64 typedef	union {
65   NSUInteger    addr;	/* Always present */
66 #if	((GSUNION_TYPES) & GSUNION_OBJ)
67   id		obj;
68   NSObject	*nso;
69 #endif
70 #if	((GSUNION_TYPES) & GSUNION_CLS)
71   Class		cls;
72 #endif
73 #if	((GSUNION_TYPES) & GSUNION_SEL)
74   SEL		sel;
75 #endif
76 #if	((GSUNION_TYPES) & GSUNION_NSINT)
77   NSInteger 	nsi;
78   NSUInteger	nsu;
79 #endif
80 #if	((GSUNION_TYPES) & GSUNION_PTR)
81   void		*ptr;
82   const void	*cptr;
83   char		*str;
84   const char	*cstr;
85 #endif
86 
87 /* Warning ... if this value is declared in the union, and its type is not
88  * the same size as a pointer, then care must be taken in case of confusion
89  * caused when an assignment to a variable using one of the union's types
90  * causes part of the variable to ebe left with undefined content from the
91  * point of view of another of the union's types.
92  */
93 #if	defined(GSUNION_EXTRA)
94   GSUNION_EXTRA	ext;
95 #endif
96 } GSUNION;
97 
98 #endif
99 
100