1.\" $NetBSD: typeof.3,v 1.2 2010/12/19 08:10:09 jruoho Exp $ 2.\" 3.\" Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25.\" POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd December 19, 2010 28.Dt TYPEOF 3 29.Os 30.Sh NAME 31.Nm typeof 32.Nd GNU extension for type of an expression 33.Sh SYNOPSIS 34.Ft type 35.Fn typeof "expression" 36.Sh DESCRIPTION 37The 38.Fn typeof 39construct can be used to obtain the type of an expression. 40The syntax is comparable to that of 41.Fn sizeof , 42but semantically 43.Fn typeof 44operates like a type name defined with 45.Em typedef . 46.Sh EXAMPLES 47The following is a typical example of a type-generic macro: 48.Bd -literal -offset indent 49#define MAX(a, b) ({ \\ 50 typeof(a) _a = (a); \\ 51 typeof(b) _b = (b); \\ 52 _a > _b ? _a : _b; \\ 53}) 54.Ed 55.Sh SEE ALSO 56.Xr gcc 1 , 57.Xr __alignof__ 3 , 58.Xr attribute 3 , 59.Xr offsetof 3 60.Sh CAVEATS 61The 62.Fn typeof 63construct is a non-standard, compiler-specific extension. 64