Re: portability sanity check

2001-02-23 Thread Jacques A. Vidrine
On Wed, Feb 21, 2001 at 05:28:31PM +0100, Poul-Henning Kamp wrote: > >Type-safety is a cruch for the weak-minded. ^ > As an old assembler programmer I couldn't agree more, but in a project > like FreeBSD we have to realize that not everybody is that. Heh, I was just cleani

Re: portability sanity check

2001-02-22 Thread Warner Losh
In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: : Likewise if the first member were a more complex data type, but : nevertheless the same between the different structures. : : It seems safe to me, but I can't explain why :-) It is obfuscated 'C', but it is safe. The standard require

Re: portability sanity check

2001-02-22 Thread Jacques A. Vidrine
On Wed, Feb 21, 2001 at 08:53:57AM -0700, Warner Losh wrote: > The standard requires that (void *) &foo == (void *) &foo->s Thanks, that is what I was trying to track down but couldn't find it. I also thought that perhaps a structure has the same requirement alignments as its first member ... I

Re: portability sanity check

2001-02-22 Thread Jacques A. Vidrine
On Wed, Feb 21, 2001 at 05:13:35PM +0100, Poul-Henning Kamp wrote: > In message <[EMAIL PROTECTED]>, Warner Losh writes: > >In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: > >: Likewise if the first member were a more complex data type, but > >: nevertheless the same between the differ

Re: portability sanity check

2001-02-22 Thread Jacques A. Vidrine
On Wed, Feb 21, 2001 at 09:56:08AM -0700, Warner Losh wrote: > There is some verbage in the structure layout part of the standard > that makes this a logical conclusion. > > However, it is overly tricky code. But then again to do the generic > sort of thing you want to do, you have to resort to

Re: portability sanity check

2001-02-21 Thread Matt Dillon
:Is the following portable and safe? : :Given n different structure declarations, where each structure begins :with the same member type, can any instance of any of the structures :be cast to the (pointer) type of the first member? : :e.g. : : struct foo { : const char *s; : ... :

Re: portability sanity check

2001-02-21 Thread Warner Losh
In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: : On Wed, Feb 21, 2001 at 08:53:57AM -0700, Warner Losh wrote: : > The standard requires that (void *) &foo == (void *) &foo->s : : Thanks, that is what I was trying to track down but couldn't find it. : I also thought that perhaps a st

Re: portability sanity check

2001-02-21 Thread Poul-Henning Kamp
In message <[EMAIL PROTECTED]>, "Jacques A. Vidrine" writes: >On Wed, Feb 21, 2001 at 05:13:35PM +0100, Poul-Henning Kamp wrote: >> In message <[EMAIL PROTECTED]>, Warner Losh writes: >> >In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: >> >: Likewise if the first member were a more com

portability sanity check

2001-02-21 Thread Jacques A. Vidrine
Is the following portable and safe? Given n different structure declarations, where each structure begins with the same member type, can any instance of any of the structures be cast to the (pointer) type of the first member? e.g. struct foo { const char *s; ... }; struc

Re: portability sanity check

2001-02-21 Thread Poul-Henning Kamp
In message <[EMAIL PROTECTED]>, Warner Losh writes: >In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: >: Likewise if the first member were a more complex data type, but >: nevertheless the same between the different structures. >: >: It seems safe to me, but I can't explain why :-) > >

Re: portability sanity check

2001-02-21 Thread Warner Losh
In message <[EMAIL PROTECTED]> "Jacques A. Vidrine" writes: : When you say ``resort to C macros,'' do you mean macros to hide the : `type punning', or do you have something else in mind? I had the queue macros in mind. Hiding the type punning behind a macro helps make sure it is used right, but