Message-ID: <94d86bd72ae5132919da743a2a044bdb.squirrel@sourcetrek.com> In-Reply-To: <55B244BB.3030402@xenomai.org> References: <5515ffa50f7d05764c02821440947bc5.squirrel@sourcetrek.com> <55B244BB.3030402@xenomai.org> Date: Fri, 24 Jul 2015 16:04:19 +0200 From: "Gilles Chanteperdrix" MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand List-Id: Discussions about the Xenomai project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Philippe Gerum Cc: xenomai@xenomai.org Philippe Gerum wrote: > On 07/24/2015 03:20 PM, Gilles Chanteperdrix wrote: >> >> git repository hosting wrote: >>> Module: xenomai-3 >>> Branch: next >>> Commit: 2a584d6763c64f9e566b5f53094d57dd72688857 >>> URL: >>> http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2a584d6763c64f9e566b5f53094d57dd72688857 >>> >>> Author: Philippe Gerum >>> Date: Thu Jul 23 19:13:29 2015 +0200 >>> >>> boilerplate: add offsetof() shorthand >>> >>> --- >>> >>> include/boilerplate/compiler.h | 4 ++++ >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/include/boilerplate/compiler.h >>> b/include/boilerplate/compiler.h >>> index e27d165..876e004 100644 >>> --- a/include/boilerplate/compiler.h >>> +++ b/include/boilerplate/compiler.h >>> @@ -54,4 +54,8 @@ >>> #define __aligned(__n) __attribute__((aligned (__n))) >>> #endif >>> >>> +#ifndef offsetof >>> +#define offsetof(__type, __member) __builtin_offsetof(__type, >>> __member) >>> +#endif >> >> offsetof should be defined by glibc headers. By adding a definition, you >> risk a compiler warning about multiple definitions if someone uses the >> proper glibc header. >> >> > > There is hardly any risk of that kind when using the gcc builtin. > builtin or not, if I compile the following program: #include #include #include #define offsetof(__type, __member) __builtin_offsetof(__type,__member) int main(void) { printf("Hello\n"); return EXIT_SUCCESS; } I get the following warning: $ gcc -Wall -W -o foo foo.c foo.c:5:0: warning: "offsetof" redefined [enabled by default] #define offsetof(__type, __member) __builtin_offsetof(__type,__member) ^ In file included from /usr/include/alloca.h:24:0, from /usr/include/stdlib.h:491, from foo.c:3: /usr/lib64/gcc/x86_64-slackware-linux/4.8.2/include/stddef.h:413:0: note: this is the location of the previous definition #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) ^ -- Gilles. https://click-hack.org