$NetBSD: __builtin_types_compatible_p.3,v 1.1 2010/12/21 15:05:02 jruoho Exp $

Copyright (c) 2010 Jukka Ruohonen <jruohonen@iki.fi>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

.Dd December 21, 2010 .Dt __BUILTIN_TYPES_COMPATIBLE_P 3 .Os .Sh NAME .Nm __builtin_types_compatible_p .Nd GNU extension to check equivalent types .Sh SYNOPSIS .Ft int .Fn __builtin_types_compatible_p "type_a" "type_b" .Sh DESCRIPTION The .Fn __builtin_types_compatible_p is a .Tn GNU extension for determining whether two types are equivalent. If .Fa type_a is equivalent to .Fa type_b , a value 1 is returned. Otherwise .Fn __builtin_types_compatible_p returns 0.

p The following remarks should be taken into account. l -enum -offset indent t The architecture-specific size of the two types does not have an impact on the result. For example, .Fn sizeof "char *" and .Fn sizeof "int" result the same value on i386, but the types naturally are not equivalent. t Type qualifiers are ignored. The function returns the same value for .Vt long and .Vt const long . t The amount of pointer indirection affects the result. For example, .Vt double * is not equivalent to .Vt double ** . t Two types defined with .Em typedef are equivalent if and only if their underlying types are equivalent. t The .Em enum type is a special case in that two .Em enum types are not considered equivalent. .El .Sh EXAMPLES The following example combines .Fn __builtin_types_compatible_p and the .Xr typeof 3 construct: d -literal -offset indent #define __COMPARE_TYPES(v, t) \\ __builtin_types_compatible_p(__typeof__(v), t) ... if (__COMPARE_TYPES(p, double) != 0) err(EX_DATAERR, "invalid type"); .Ed .Sh SEE ALSO .Xr gcc 1 , .Xr __builtin_constant_p 3 , .Xr typeof 3 .Sh CAVEATS This is a non-standard, compiler-specific extension.