* [Xenomai] Why does mqueue.h define mqd_t as unsigned @ 2015-04-09 20:52 Phil Mitchell 2015-04-09 21:07 ` Gilles Chanteperdrix 2015-04-09 21:11 ` Paul Janzen 0 siblings, 2 replies; 10+ messages in thread From: Phil Mitchell @ 2015-04-09 20:52 UTC (permalink / raw) To: Xenomai Mailing List Dear All, mqueue.h defines mqd_t as an unsigned long. The function mq_open returns type mqd_t and states that -1 is returned in case of error. Is mqd_t defined incorrectly or am I missing something? Thanks, Phil Mitchell ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 20:52 [Xenomai] Why does mqueue.h define mqd_t as unsigned Phil Mitchell @ 2015-04-09 21:07 ` Gilles Chanteperdrix 2015-04-10 18:55 ` Gilles Chanteperdrix 2015-04-09 21:11 ` Paul Janzen 1 sibling, 1 reply; 10+ messages in thread From: Gilles Chanteperdrix @ 2015-04-09 21:07 UTC (permalink / raw) To: Phil Mitchell; +Cc: Xenomai Mailing List On Thu, Apr 09, 2015 at 04:52:26PM -0400, Phil Mitchell wrote: > Dear All, > > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > type mqd_t and states that -1 is returned in case of error. > > Is mqd_t defined incorrectly or am I missing something? The specification does not say what mqd_t should be and says that mq_open returns (mqd_t)-1, not -1, and (unsigned long)-1 is valid, so, this is valid even if a bit strange. mqd_t is an opaque type for the user anyway, so its actual type should not matter to you. But in fact we do not even need a long type since what is returned is a file descriptor, so, we could have typedef int mqd_t like glibc. -- Gilles. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 21:07 ` Gilles Chanteperdrix @ 2015-04-10 18:55 ` Gilles Chanteperdrix 0 siblings, 0 replies; 10+ messages in thread From: Gilles Chanteperdrix @ 2015-04-10 18:55 UTC (permalink / raw) To: Phil Mitchell; +Cc: Xenomai Mailing List On Thu, Apr 09, 2015 at 11:07:13PM +0200, Gilles Chanteperdrix wrote: > On Thu, Apr 09, 2015 at 04:52:26PM -0400, Phil Mitchell wrote: > > Dear All, > > > > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > > type mqd_t and states that -1 is returned in case of error. > > > > Is mqd_t defined incorrectly or am I missing something? > > The specification does not say what mqd_t should be and says that > mq_open returns (mqd_t)-1, not -1, and (unsigned long)-1 is valid, > so, this is valid even if a bit strange. mqd_t is an opaque type for > the user anyway, so its actual type should not matter to you. > > But in fact we do not even need a long type since what is returned > is a file descriptor, so, we could have typedef int mqd_t like > glibc. In fact mqd_t is already an int in the following case: - in kernel-space where it gets defined by kernel/types.h - in user-space when the glibc has mqueue.h, since then include that header. The only remaining cases where we use unsigned long are: - glibc without an mqueue.h, but I believe they are rare now a days - when compiling for xeno-sim, which has been unusable with recent compilers for years now. So, I think we do not care. -- Gilles. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 20:52 [Xenomai] Why does mqueue.h define mqd_t as unsigned Phil Mitchell 2015-04-09 21:07 ` Gilles Chanteperdrix @ 2015-04-09 21:11 ` Paul Janzen 2015-04-09 22:09 ` Lennart Sorensen 1 sibling, 1 reply; 10+ messages in thread From: Paul Janzen @ 2015-04-09 21:11 UTC (permalink / raw) To: Phil Mitchell; +Cc: Xenomai Mailing List Phil Mitchell <p.mitch@gmail.com> writes: > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > type mqd_t and states that -1 is returned in case of error. > > Is mqd_t defined incorrectly or am I missing something? The man page says mq_open returns (mqd_t)(-1) on error. If you include that cast when you test the return value it works, even if mqd_t is unsigned. (Or a pointer.) -- Paul ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 21:11 ` Paul Janzen @ 2015-04-09 22:09 ` Lennart Sorensen 2015-04-09 22:17 ` Gilles Chanteperdrix 0 siblings, 1 reply; 10+ messages in thread From: Lennart Sorensen @ 2015-04-09 22:09 UTC (permalink / raw) To: Paul Janzen; +Cc: Xenomai Mailing List On Thu, Apr 09, 2015 at 02:11:53PM -0700, Paul Janzen wrote: > Phil Mitchell <p.mitch@gmail.com> writes: > > > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > > type mqd_t and states that -1 is returned in case of error. > > > > Is mqd_t defined incorrectly or am I missing something? > > The man page says mq_open returns (mqd_t)(-1) on error. If you include > that cast when you test the return value it works, even if mqd_t is > unsigned. (Or a pointer.) Yuck! Some of us try to avoid explicit casts since they are a great way to hide bugs in ways the compiler can't help you find. Making a cast required by design seems like a major design bug that ought to be fixed. -- Len Sorensen ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 22:09 ` Lennart Sorensen @ 2015-04-09 22:17 ` Gilles Chanteperdrix 2015-04-09 22:29 ` Gilles Chanteperdrix 2015-04-10 14:44 ` Lennart Sorensen 0 siblings, 2 replies; 10+ messages in thread From: Gilles Chanteperdrix @ 2015-04-09 22:17 UTC (permalink / raw) To: Lennart Sorensen; +Cc: Xenomai Mailing List On Thu, Apr 09, 2015 at 06:09:56PM -0400, Lennart Sorensen wrote: > On Thu, Apr 09, 2015 at 02:11:53PM -0700, Paul Janzen wrote: > > Phil Mitchell <p.mitch@gmail.com> writes: > > > > > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > > > type mqd_t and states that -1 is returned in case of error. > > > > > > Is mqd_t defined incorrectly or am I missing something? > > > > The man page says mq_open returns (mqd_t)(-1) on error. If you include > > that cast when you test the return value it works, even if mqd_t is > > unsigned. (Or a pointer.) > > Yuck! > > Some of us try to avoid explicit casts since they are a great way to > hide bugs in ways the compiler can't help you find. > > Making a cast required by design seems like a major design bug that > ought to be fixed. This design is specified by POSIX. This looks like a "fighting the windmill" case. -- Gilles. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 22:17 ` Gilles Chanteperdrix @ 2015-04-09 22:29 ` Gilles Chanteperdrix 2015-04-09 23:17 ` Lowell Gilbert 2015-04-10 14:44 ` Lennart Sorensen 1 sibling, 1 reply; 10+ messages in thread From: Gilles Chanteperdrix @ 2015-04-09 22:29 UTC (permalink / raw) To: Lennart Sorensen; +Cc: Xenomai Mailing List On Fri, Apr 10, 2015 at 12:17:18AM +0200, Gilles Chanteperdrix wrote: > On Thu, Apr 09, 2015 at 06:09:56PM -0400, Lennart Sorensen wrote: > > On Thu, Apr 09, 2015 at 02:11:53PM -0700, Paul Janzen wrote: > > > Phil Mitchell <p.mitch@gmail.com> writes: > > > > > > > mqueue.h defines mqd_t as an unsigned long. The function mq_open returns > > > > type mqd_t and states that -1 is returned in case of error. > > > > > > > > Is mqd_t defined incorrectly or am I missing something? > > > > > > The man page says mq_open returns (mqd_t)(-1) on error. If you include > > > that cast when you test the return value it works, even if mqd_t is > > > unsigned. (Or a pointer.) > > > > Yuck! > > > > Some of us try to avoid explicit casts since they are a great way to > > hide bugs in ways the compiler can't help you find. > > > > Making a cast required by design seems like a major design bug that > > ought to be fixed. > > This design is specified by POSIX. This looks like a "fighting the > windmill" case. I think the upside of this design is that it allows mqd_t being implemented as a pointer or as an integer, this gives freedom to the implementer by making the type opaque. -- Gilles. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 22:29 ` Gilles Chanteperdrix @ 2015-04-09 23:17 ` Lowell Gilbert 0 siblings, 0 replies; 10+ messages in thread From: Lowell Gilbert @ 2015-04-09 23:17 UTC (permalink / raw) To: Gilles Chanteperdrix; +Cc: Xenomai Mailing List Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org> writes: > On Fri, Apr 10, 2015 at 12:17:18AM +0200, Gilles Chanteperdrix wrote: >> This design is specified by POSIX. This looks like a "fighting the >> windmill" case. > > I think the upside of this design is that it allows mqd_t being > implemented as a pointer or as an integer, this gives freedom to the > implementer by making the type opaque. Yes, but in other cases POSIX specified symbolic constants rather than numeric values for exactly that problem. It's possible that somebody just made a mistake by not doing that here, but I would venture to guess that there was probably an issue with existing code that led to this hack. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-09 22:17 ` Gilles Chanteperdrix 2015-04-09 22:29 ` Gilles Chanteperdrix @ 2015-04-10 14:44 ` Lennart Sorensen 2015-04-10 14:50 ` Gilles Chanteperdrix 1 sibling, 1 reply; 10+ messages in thread From: Lennart Sorensen @ 2015-04-10 14:44 UTC (permalink / raw) To: Gilles Chanteperdrix; +Cc: Xenomai Mailing List On Fri, Apr 10, 2015 at 12:17:18AM +0200, Gilles Chanteperdrix wrote: > This design is specified by POSIX. This looks like a "fighting the > windmill" case. Yeah "Posix says so" always wins any argument it seems. :) -- Len Sorensen ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Xenomai] Why does mqueue.h define mqd_t as unsigned 2015-04-10 14:44 ` Lennart Sorensen @ 2015-04-10 14:50 ` Gilles Chanteperdrix 0 siblings, 0 replies; 10+ messages in thread From: Gilles Chanteperdrix @ 2015-04-10 14:50 UTC (permalink / raw) To: Lennart Sorensen; +Cc: Xenomai Mailing List On Fri, Apr 10, 2015 at 10:44:10AM -0400, Lennart Sorensen wrote: > On Fri, Apr 10, 2015 at 12:17:18AM +0200, Gilles Chanteperdrix wrote: > > This design is specified by POSIX. This looks like a "fighting the > > windmill" case. > > Yeah "Posix says so" always wins any argument it seems. :) Adding #define MQ_FAILED ((mqd_t)-1) in your application and using it makes your application portable. Adding it to Xenomai headers and using it in your application makes your application non portable. If the POSIX standard added this definition, then if you wanted your application to be portable, you would want it to support previous POSIX standards, so you would still add this definition to your application (with an added ifdef on the posix standard level). So, all and all, adding #define MQ_FAILED ((mqd_t)-1) to your application and move on wins the argument. -- Gilles. ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-04-10 18:55 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-04-09 20:52 [Xenomai] Why does mqueue.h define mqd_t as unsigned Phil Mitchell 2015-04-09 21:07 ` Gilles Chanteperdrix 2015-04-10 18:55 ` Gilles Chanteperdrix 2015-04-09 21:11 ` Paul Janzen 2015-04-09 22:09 ` Lennart Sorensen 2015-04-09 22:17 ` Gilles Chanteperdrix 2015-04-09 22:29 ` Gilles Chanteperdrix 2015-04-09 23:17 ` Lowell Gilbert 2015-04-10 14:44 ` Lennart Sorensen 2015-04-10 14:50 ` Gilles Chanteperdrix
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.