-mms-bitfields

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

-mms-bitfields

John Emmas
Hi there - over on the gtk-app-devel list, Tor Lillqvist and I were
discussing the compiler flag -mms-bitfields.  When building a gtk-win32 app,
this is needed to ensure that structs will be aligned to the traditional
Microsoft (8-byte) alignment standard.

But what about the rest of MinGW?  If I were to install MinGW together with
some (non-gtk) libraries (let's say libintl and libxml2) would they
typically be built with the -mms-bitfields flag?  If not, is there a
recommended strategy for designing a MinGW app that needs to interface both
with gtk and non-gtk libraries?  If there's any requirement to exchange
information using structs, won't this cause some big headaches?

Thanks,

John


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming
Reply | Threaded
Open this post in threaded view
|

Re: -mms-bitfields

Danny Smith

>
>
> Hi there - over on the gtk-app-devel list, Tor Lillqvist and I were
> discussing the compiler flag -mms-bitfields.  When building a
> gtk-win32 app,
> this is needed to ensure that structs will be aligned to the
> traditional
> Microsoft (8-byte) alignment standard.
>

No,  8-byte  structure packing is default on mingw32
 -mms-bitfields is much more specific

It is explained in gcc.info.  
<quote>
     MSVC interprets zero-length bitfields in the following ways:

       1. If a zero-length bitfield is inserted between two bitfields
          that would normally be coalesced, the bitfields will not be
          coalesced.

          For example:

               struct
                {
                  unsigned long bf_1 : 12;
                  unsigned long : 0;
                  unsigned long bf_2 : 12;
                } t1;

          The size of `t1' would be 8 bytes with the zero-length
          bitfield.  If the zero-length bitfield were removed, `t1''s
          size would be 4 bytes.

       2. If a zero-length bitfield is inserted after a bitfield,
          `foo', and the alignment of the zero-length bitfield is
          greater than the member that follows it, `bar', `bar' will be
          aligned as the type of the zero-length bitfield.

          For example:

               struct
                {
                  char foo : 4;
                  short : 0;
                  char bar;
                } t2;

               struct
                {
                  char foo : 4;
                  short : 0;
                  double bar;
                } t3;

          For `t2', `bar' will be placed at offset 2, rather than
          offset 1.  Accordingly, the size of `t2' will be 4.  For
          `t3', the zero-length bitfield will not affect the alignment
          of `bar' or, as a result, the size of the structure.

          Taking this into account, it is important to note the
          following:

            1. If a zero-length bitfield follows a normal bitfield, the
               type of the zero-length bitfield may affect the
               alignment of the structure as whole. For example, `t2'
               has a size of 4 bytes, since the zero-length bitfield
               follows a normal bitfield, and is of type short.

            2. Even if a zero-length bitfield is not followed by a
               normal bitfield, it may still affect the alignment of
               the structure:

                    struct
                     {
                       char foo : 6;
                       long : 0;
                     } t4;

               Here, `t4' will take up 4 bytes.

       3. Zero-length bitfields following non-bitfield members are
          ignored:

               struct
                {
                  char foo;
                  long : 0;
                  char bar;
                } t5;

          Here, `t5' will take up 2 bytes.
</quote>


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming
Reply | Threaded
Open this post in threaded view
|

Re: -mms-bitfields

Tor Lillqvist
In reply to this post by John Emmas
> But what about the rest of MinGW?  If I were to install MinGW together with
> some (non-gtk) libraries (let's say libintl and libxml2) would they
> typically be built with the -mms-bitfields flag?

It doesn't matter unless the public API of such libraries include
struct with bitfields that happen to be differently aligned with and
without -mms-bitfields. Neither libintl or libxml2 use any such
structs in their APIs.

(A potentially more serious problem with libxml2 is that it's API
includes iconv_t fields in some struct. If you use these APIs, you
must be sure you are using the same iconv implementation as your copy
of libxml2 uses.)

> If not, is there a
> recommended strategy for designing a MinGW app that needs to interface both
> with gtk and non-gtk libraries?  If there's any requirement to exchange
> information using structs, won't this cause some big headaches?

Indeed. Luckily it doesn't seem to occur often in practise.

--tml

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming
Reply | Threaded
Open this post in threaded view
|

Re: -mms-bitfields

Keith Marshall
On Sunday 08 February 2009 10:22:10 Tor Lillqvist wrote:

> > But what about the rest of MinGW?  If I were to install MinGW
> > together with some (non-gtk) libraries (let's say libintl and
> > libxml2) would they typically be built with the -mms-bitfields
> > flag?
>
> It doesn't matter unless the public API of such libraries include
> struct with bitfields that happen to be differently aligned with
> and without -mms-bitfields. Neither libintl or libxml2 use any such
> structs in their APIs.
>
> (A potentially more serious problem with libxml2 is that it's API
> includes iconv_t fields in some struct. If you use these APIs, you
> must be sure you are using the same iconv implementation as your
> copy of libxml2 uses.)

Hence the preference, already expressed by Earnie, for building all
libraries from source; if you've built it all yourself, you can have
much greater confidence in the consistency of the APIs.

--

Regards,
Keith.

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming
Reply | Threaded
Open this post in threaded view
|

Re: -mms-bitfields

John Emmas
----- Original Message -----
From: "Keith Marshall" <[hidden email]>
Subject: Re: [Mingw-users] -mms-bitfields
>
> Hence the preference, already expressed by Earnie, for building all
> libraries from source; if you've built it all yourself, you can have
> much greater confidence in the consistency of the APIs.
>
Yes, I agree entirely but this is something that needs to be borne in mind
by anyone who wants to use gtk-win32, together with the rest of MinGW
without building from source.  There seems to be an accident waiting to
happen here - and the fact that it seems to have caused so few problems is
largely down to luck.

Cheers,

John

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming
Reply | Threaded
Open this post in threaded view
|

Re: -mms-bitfields

Earnie Boyd

Quoting John Emmas <[hidden email]>:

> ----- Original Message -----
> From: "Keith Marshall" <[hidden email]>
> Subject: Re: [Mingw-users] -mms-bitfields
>>
>> Hence the preference, already expressed by Earnie, for building all
>> libraries from source; if you've built it all yourself, you can have
>> much greater confidence in the consistency of the APIs.
>>
> Yes, I agree entirely but this is something that needs to be borne in mind
> by anyone who wants to use gtk-win32, together with the rest of MinGW
> without building from source.  There seems to be an accident waiting to
> happen here - and the fact that it seems to have caused so few problems is
> largely down to luck.
>

There is a reason that all UNIX installations require building the
objects on the destination computer.  That reason is one of binary
compatibility with all libraries.  I employ that strategy for the FOSS
software I install.  And yes, if you install a precompiled version of
any library you're taking luck out to lunch.

Earnie

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

_______________________________________________
This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) HTML/MIME encoded mail
3) Improper quoting
4) Improper trimming