From: Sascha Wildner Date: Mon, 21 Apr 2014 14:08:47 +0000 (+0200) Subject: Add the header for C11 conformance. X-Git-Tag: v3.9.0~99 X-Git-Url: https://gitweb.dragonflybsd.org/~tuxillo/dragonfly.git/commitdiff_plain/787c358097ac8d11c406faee6f876ddc72d5e0f2 Add the header for C11 conformance. Per clause 7.15 from the final draft. Along with it, add some helper macros to . While here, adjust an #ifdef in . Taken-from: FreeBSD --- diff --git a/include/Makefile b/include/Makefile index 4d7701a73f..f781d88ea9 100644 --- a/include/Makefile +++ b/include/Makefile @@ -20,7 +20,7 @@ INCS= a.out.h ar.h assert.h bitstring.h cpio.h ctype.h db.h \ ranlib.h readpassphrase.h regex.h \ res_update.h resolv.h re_comp.h rmd160.h \ runetype.h search.h setjmp.h sgtty.h \ - signal.h spawn.h stab.h stdarg.h stdbool.h \ + signal.h spawn.h stab.h stdalign.h stdarg.h stdbool.h \ stddef.h stdint.h stdio.h stdlib.h \ string.h stringlist.h strings.h struct.h sysexits.h \ tar.h tgmath.h time.h \ diff --git a/include/stdalign.h b/include/stdalign.h new file mode 100644 index 0000000000..37a93fa88c --- /dev/null +++ b/include/stdalign.h @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2012 Ed Schouten + * 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 AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: head/include/stdalign.h 228879 2011-12-25 20:51:40Z ed $ + */ + +#ifndef __alignas_is_defined +#define __alignas_is_defined 1 + +#if !defined(__cplusplus) || __cplusplus < 201103L +#include +#define alignas _Alignas +#endif + +#endif /* !__alignas_is_defined */ + +#ifndef __alignof_is_defined +#define __alignof_is_defined 1 + +#if !defined(__cplusplus) || __cplusplus < 201103L +#include +#define alignof _Alignof +#endif + +#endif /* !__alignof_is_defined */ diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index d7d0c3d46e..9f3d7ac2b5 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -424,15 +424,37 @@ #define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) #endif +/* + * Keywords added in C11. + */ + +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + /* * Keywords added in C11. */ #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L -#define _Noreturn __dead2 +#if !__has_extension(c_alignas) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_alignas) +#define _Alignas(x) alignas(x) +#else +/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ +#define _Alignas(x) __aligned(x) +#endif +#endif -#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(x) alignof(x) +#else +#define _Alignof(x) __alignof(x) +#endif + +#define _Noreturn __dead2 #if !__has_extension(c_static_assert) #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ @@ -448,6 +470,8 @@ #endif #endif +#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + #if defined(_KERNEL) && !defined(CTASSERT) #define CTASSERT(x) _Static_assert(x, \ "compile-time assertion failed")