🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51819

How to get the type of a variable or an expression as an integer value?

#51819
From: meissner
Date: Fri, 19 Mar 1993 18:47
35 lines
2027 bytes
| Dear Sirs,
| I need help for a problem that seems very hard to solve for me but
| probably it's a very naive question for developers of gcc.
| I need a way to get a unique  integer value for any (pre-defined
| or user defined) type i.e., I need some function (let's call it
| c_type()) that outputs an integer type descriptor for any variable
| or expression.

It is not documented, but you can use the __builtin_classify_type
function, which will return an integer based on the type of the
argument.  The include file typeclass.h in the compiler release
directory (& included below), give the values returned:

	/* Values returned by __builtin_classify_type.  */

	enum type_class
	{
	  no_type_class = -1,
	  void_type_class, integer_type_class, char_type_class,
	  enumeral_type_class, boolean_type_class,
	  pointer_type_class, reference_type_class, offset_type_class,
	  real_type_class, complex_type_class,
	  function_type_class, method_type_class,
	  record_type_class, union_type_class,
	  array_type_class, string_type_class, set_type_class, file_type_class,
	  lang_type_class
	};

Note that all structures return the same value, as do functions, etc.

--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

You are in a twisty little passage of standards, all conflicting.
Technical Details
Message-ID: <9303191818.AA26871@curley.osf.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!osf.ORG!meissner
References: meissner@osf.ORG

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,8bd4803816986a31,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-03-19 10:58:24 PST
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!osf.ORG!meissner
From: meissner@osf.ORG
Newsgroups: gnu.gcc.help
Subject: How to get the type of a variable or an expression as an integer value?
Date: 19 Mar 1993 13:47:00 -0500
Organization: Gnus Not Usenet
Lines: 35
Sender: daemon@cis.ohio-state.edu
Distribution: gnu
Message-ID: <9303191818.AA26871@curley.osf.org>
References: meissner@osf.ORG