Re: C Structures

From: Rick VanNorman <rick_at_forth.com>
Date: Mon, 16 Apr 2001 06:59:41 -0700

The only packing that should be done in any interface to
the Windows API is exactly whatever Microsoft says. No one
can use arbitrary C compiler packing, #pragma or otherwise,
when the API is already hardcoded with a set of conventions.

That said, all structures in SwiftForth are essentially
built by hand, just like in assembly language programming.
Even when one uses the Swoop class mechanism to build a
data structure, one can pack it any way one chooses.

But, remember, if you're going to call Windows, pack the
structure _JUST LIKE WINDOWS SAYS YOU SHOULD_ .

I think what Mike Ghan is trying to do is to build a
"rule of thumb" in order to be able to convert simply
from the structures specified by the Windows api to
a SwiftForth compatable structure, which isn't too
hard.

Best of luck,
Rick VanNorman

*********** REPLY SEPARATOR ***********

On 4/16/2001 at 9:06 AM John Whitt wrote:

>No amount of documentation will help if you do not know how a structure
>is
>packed immediately before passing it to an API. I have seen "C" program
>with multiple occurrences of
>#pragma pack statements buried with #include files that are make it almost=

>impossible to figure out how a structure is packed. For instance a SCI
>driver typically need structure member that are not padded, exp #pragma
>pack(1) . A Win32 API may not require this so later in an include file
>there may be a #pragma pack which changes to compiler back to the default
>packing. Also be aware that the /ZPn option does not override the #pragma
>pack option.
>
>What makes this problem even worse is when trying to interface to
>different
>languages such a VB or Delphi. Each of these languages pad structures
> differently than "C" and these compilers do not have options to changes
>the packing.
>
>I think the Conrad's method of determining the offset into the structure
>using offsetof is right on!
>
>Does Swiftforth have the ability to change the structure packing? If so
>this would be an easier way to address the issue because once the
>structure
>packing was determined a Swiftforth option could be enabled to padd the
>structure appropiately.

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Received on Mon Apr 16 2001 - 07:01:57 PDT


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.