Re: [current tinderbox] failure on ...all...

From: Giorgos Keramidas (keramida_at_freebsd.org)
Date: 06/10/05

  • Next message: Tarc: "Re: Problem with TCP/IP stack?"
    Date: Fri, 10 Jun 2005 13:28:13 +0300
    To: Ruslan Ermilov <ru@freebsd.org>
    
    

    On 2005-06-10 12:46, Ruslan Ermilov <ru@freebsd.org> wrote:
    >On Fri, Jun 10, 2005 at 11:16:27AM +0200, Stefan Farfeleder wrote:
    >>On Fri, Jun 10, 2005 at 11:06:16AM +0200, Dag-Erling Sm?rgrav wrote:
    >>>Joseph Koshy <joseph.koshy@gmail.com> writes:
    >>>> Dag-Erling Sm?rgrav <des@des.no> writes:
    >>>> > It also seems strange to me that you on the one hand introduce a
    >>>> > new struct to separate MD and MI interfaces, and on the other hand
    >>>> > continue to assume that they are assignment-compatible.
    >>>> I'd be very surprised if two C structures with identical definitions
    >>>> were not assignment compatible.
    >>>
    >>> I wouldn't be surprised if the standard says they aren't.
    >>> Unfortunately, my copy is at home.
    >>
    >> Do you mean the following?
    >>
    >> struct t1 { int a; } x;
    >> struct t2 { int a; } y = { 42 };
    >> x = y;
    >>
    >> The types `struct t1' and `struct t2' are not compatible and thus not
    >> assignable. See 6.2.7 and 6.5.16.1.
    >
    > If you're to byte-copy say t1 to t2, is it guaranteed to work? That
    > is, do both types are guaranteed to have the same size and alignment
    > of their structure members? I'm pretty sure this is guaranteed, as
    > lot of code assumes this, for example, the sockaddr* structures.

    That would be very hard to guarantee if two different modules that use
    the types are compiled with different alignment options, right?

            /* header1.h */
            struct t1 {short t1s; int t1a;};

            /* header2.h */
            struct t2 {short t2s; int t2a;};

            /* module1.c */
            #include "header1.h"
            struct t1 x;

            /* module2.c */
            #include "header1.h"
            #include "header2.h"
            extern struct t1 x;
            struct t2 y;

    If the two modules are compiled with different options that may affect
    struct member alignment, how would one ensure that it is correct to
    use code like this in module.c?

            y.t2s = 10;
            y.t2a = 100;
            memcpy(&x, &y, sizeof(x));

    Even the use of sizeof(x) is tricky here, since there is no guarantee
    that sizeof(x) < sizeof(y).

    _______________________________________________
    freebsd-current@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-current
    To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"


  • Next message: Tarc: "Re: Problem with TCP/IP stack?"

    Relevant Pages

    • Re: [current tinderbox] failure on ...all...
      ... do both types are guaranteed to have the same size and alignment ... >> of their structure members? ... > That would be very hard to guarantee if two different modules that use ... FreeBSD committer ...
      (freebsd-current)
    • Re: Differences between one-dimensional arrays in Java and C
      ... >> But using GCD still isn't enough to guarantee that the minimum ... >> alignment necessary will result. ... Similarly using the GCD will produce a result that is ... I agree with your comment that the "minimal alignment" of a type (the ...
      (comp.lang.c)
    • Re: Differences between one-dimensional arrays in Java and C
      ... A type's alignment requirement must be ... Normally the unneed extra space (and even 'extra_space' ... I deliberately put the pointer array second ... But using GCD still isn't enough to guarantee that the minimum ...
      (comp.lang.c)
    • Re: dereferencing or not?
      ... I gather this writes pointers and also the *next ptrs? ... them one by one) because of alignment of structure members. ... Endianness is the way of representing values in memory. ...
      (comp.unix.programmer)
    • Re: Differences between one-dimensional arrays in Java and C
      ... arcane C knowledge. ... But using GCD still isn't enough to guarantee that the minimum alignment necessary will result. ...
      (comp.lang.c)