* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand [not found] <E1ZIZjP-0001py-FB@sd-51317.xenomai.org> @ 2015-07-24 13:20 ` Gilles Chanteperdrix 2015-07-24 13:59 ` Philippe Gerum 0 siblings, 1 reply; 6+ messages in thread From: Gilles Chanteperdrix @ 2015-07-24 13:20 UTC (permalink / raw) To: xenomai 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 <rpm@xenomai.org> > 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. -- Gilles. https://click-hack.org ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand 2015-07-24 13:20 ` [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand Gilles Chanteperdrix @ 2015-07-24 13:59 ` Philippe Gerum 2015-07-24 14:04 ` Gilles Chanteperdrix 0 siblings, 1 reply; 6+ messages in thread From: Philippe Gerum @ 2015-07-24 13:59 UTC (permalink / raw) To: Gilles Chanteperdrix, xenomai 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 <rpm@xenomai.org> >> 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. -- Philippe. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand 2015-07-24 13:59 ` Philippe Gerum @ 2015-07-24 14:04 ` Gilles Chanteperdrix 2015-07-24 14:10 ` Philippe Gerum 0 siblings, 1 reply; 6+ messages in thread From: Gilles Chanteperdrix @ 2015-07-24 14:04 UTC (permalink / raw) To: Philippe Gerum; +Cc: xenomai 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 <rpm@xenomai.org> >>> 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 <stddef.h> #include <stdio.h> #include <stdlib.h> #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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand 2015-07-24 14:04 ` Gilles Chanteperdrix @ 2015-07-24 14:10 ` Philippe Gerum 2015-07-24 14:15 ` Gilles Chanteperdrix 0 siblings, 1 reply; 6+ messages in thread From: Philippe Gerum @ 2015-07-24 14:10 UTC (permalink / raw) To: Gilles Chanteperdrix; +Cc: xenomai On 07/24/2015 04:04 PM, Gilles Chanteperdrix wrote: > > 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 <rpm@xenomai.org> >>>> 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 <stddef.h> > #include <stdio.h> > #include <stdlib.h> > > #define offsetof(__type, __member) __builtin_offsetof(__type,__member) Your program is wrong in the first place, since offsetof() is defined by stddef.h. Given that 3.x assumes a modern compiler with offsetof() available from there, you are just asking for troubles, especially since you explicitly omit the guard, which is not the best way to get things working either. What can be done is including stddef.h from compiler.h, and provide a placeholder for offsetof() based on the null cast trick. That would make more sense. > > 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) > ^ > > -- Philippe. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand 2015-07-24 14:10 ` Philippe Gerum @ 2015-07-24 14:15 ` Gilles Chanteperdrix 2015-07-24 14:25 ` Philippe Gerum 0 siblings, 1 reply; 6+ messages in thread From: Gilles Chanteperdrix @ 2015-07-24 14:15 UTC (permalink / raw) To: Philippe Gerum; +Cc: xenomai Philippe Gerum wrote: > On 07/24/2015 04:04 PM, Gilles Chanteperdrix wrote: >> >> 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 <rpm@xenomai.org> >>>>> 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 <stddef.h> >> #include <stdio.h> >> #include <stdlib.h> >> >> #define offsetof(__type, __member) __builtin_offsetof(__type,__member) > > > Your program is wrong in the first place, since offsetof() is defined by > stddef.h. Given that 3.x assumes a modern compiler with offsetof() > available from there, you are just asking for troubles, especially since > you explicitly omit the guard, which is not the best way to get things > working either. I did that on purpose to illustrate the case that would happen if stddef was included after compiler.h, because the compiler stddef.h does not contain any guard. The guard in compiler.h does not work if compiler.h is included first. > > What can be done is including stddef.h from compiler.h, and provide a > placeholder for offsetof() based on the null cast trick. That would make > more sense. Not really, stddef.h has been defining offetof for ages. -- Gilles. https://click-hack.org ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand 2015-07-24 14:15 ` Gilles Chanteperdrix @ 2015-07-24 14:25 ` Philippe Gerum 0 siblings, 0 replies; 6+ messages in thread From: Philippe Gerum @ 2015-07-24 14:25 UTC (permalink / raw) To: Gilles Chanteperdrix; +Cc: xenomai On 07/24/2015 04:15 PM, Gilles Chanteperdrix wrote: > > Philippe Gerum wrote: >> On 07/24/2015 04:04 PM, Gilles Chanteperdrix wrote: >>> >>> 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 <rpm@xenomai.org> >>>>>> 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 <stddef.h> >>> #include <stdio.h> >>> #include <stdlib.h> >>> >>> #define offsetof(__type, __member) __builtin_offsetof(__type,__member) >> >> >> Your program is wrong in the first place, since offsetof() is defined by >> stddef.h. Given that 3.x assumes a modern compiler with offsetof() >> available from there, you are just asking for troubles, especially since >> you explicitly omit the guard, which is not the best way to get things >> working either. > > I did that on purpose to illustrate the case that would happen if stddef > was included after compiler.h, because the compiler stddef.h does not > contain any guard. The guard in compiler.h does not work if compiler.h is > included first. > >> >> What can be done is including stddef.h from compiler.h, and provide a >> placeholder for offsetof() based on the null cast trick. That would make >> more sense. > > Not really, stddef.h has been defining offetof for ages. > > > That is not the point, including stddef.h first in compiler.h before trying the fallback definition would prevent the issue you mentioned a sentence above. Whether the fallback implementation would ever be picked or not due to stddef.h defining offsetof() most of the time is not really an urgent issue. -- Philippe. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-07-24 14:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <E1ZIZjP-0001py-FB@sd-51317.xenomai.org>
2015-07-24 13:20 ` [Xenomai] [Xenomai-git] Philippe Gerum : boilerplate: add offsetof() shorthand Gilles Chanteperdrix
2015-07-24 13:59 ` Philippe Gerum
2015-07-24 14:04 ` Gilles Chanteperdrix
2015-07-24 14:10 ` Philippe Gerum
2015-07-24 14:15 ` Gilles Chanteperdrix
2015-07-24 14:25 ` Philippe Gerum
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.