From owner-svn-src-all@FreeBSD.ORG Thu Jan 5 10:43:04 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 88BDC1065672; Thu, 5 Jan 2012 10:43:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 73E7D8FC0C; Thu, 5 Jan 2012 10:43:04 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q05Ah4hE028124; Thu, 5 Jan 2012 10:43:04 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q05Ah4ea028122; Thu, 5 Jan 2012 10:43:04 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201201051043.q05Ah4ea028122@svn.freebsd.org> From: Ed Schouten Date: Thu, 5 Jan 2012 10:43:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r229574 - head/sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2012 10:43:04 -0000 Author: ed Date: Thu Jan 5 10:43:03 2012 New Revision: 229574 URL: http://svn.freebsd.org/changeset/base/229574 Log: Add __generic(), to be able to use a very simple _Generic(). Already introducing this allows us to be forward compatible with C11 compilers. By implementing on top of this interface, it becomes trivial to support both our existing GCC and newer compilers. Modified: head/sys/sys/cdefs.h Modified: head/sys/sys/cdefs.h ============================================================================== --- head/sys/sys/cdefs.h Thu Jan 5 10:42:19 2012 (r229573) +++ head/sys/sys/cdefs.h Thu Jan 5 10:43:03 2012 (r229574) @@ -248,6 +248,24 @@ #endif #endif +/* + * Emulation of C11 _Generic(). Unlike the previously defined C11 + * keywords, it is not possible to implement this using exactly the same + * syntax. Therefore implement something similar under the name + * __generic(). Unlike _Generic(), this macro can only distinguish + * between a single type, so it requires nested invocations to + * distinguish multiple cases. + */ + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __generic(expr, t, yes, no) \ + _Generic(expr, t: yes, default: no) +#elif __GNUC_PREREQ__(3, 1) +#define __generic(expr, t, yes, no) \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof(expr), t), yes, no) +#endif + #if __GNUC_PREREQ__(2, 96) #define __malloc_like __attribute__((__malloc__)) #define __pure __attribute__((__pure__))