home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!geac!zooid!ross
- From: Ross Ridge <ross@zooid.guild.org>
- Subject: Re: Memory alignment of struct elements
- Organization: ZOOiD BBS
- Date: Mon, 17 Aug 1992 23:08:11 GMT
- Message-ID: <1992Aug17.230811.10813@zooid.guild.org>
- References: <1992Aug12.133132.10723@Princeton.EDU> <BsxCtz.598@unx.sas.com> <adam.714060134@mcrware>
- Lines: 57
-
- adam@microware.com (Adam Goldberg) writes:
- >That's all well and good, but what if, say, you are coding an implementation
- >of LIM EMS 4.0, which takes as a parameter a structure which, in assembler,
- >looks like this:
- >
- >Parm Struct
- >MemIn dd ? ; 4 bytes
- >MemIType db ? ; 1 byte
- >MemISize dw ? ; 2 bytes
- >MemOut dd ? ; 4 bytes
- >MemOType db ? ; 1 byte
- >MemOSize dw ? ; 2 bytes
- >Parm Struct
- >
- >In C, this *could* be :
- >
- >typedef struct PARM {
- > char *MemIn, MemIType;
- > short MemISize;
- > char *MemOut, MemOType;
- > short MemOSize;
- >} PARM, *pPARM;
- >
- >Except for the addition of superflourous padding bytes. Is there any
- >standard way to FORCE the C Struct to be identical to the Asm struct?
-
- No, of course not, on some machine architechures it's impossible
- define a struct like yours without necessary, not superflourous, padding
- in assembly or not. In fact there is no standard way specfiying
- a two byte wide member value, there is no guarantee that shorts are
- this size. In fact even MS-DOS C compilers don't guarantee that the char
- pointers will be 4 bytes wide, compile this in the wrong mode and they'll
- be 2 bytes wide.
-
- >No, I didn't think so. There ought to be, though. I've been forced to
- >do nasty things like:
- >
- >typedef struct PARM {
- > char MemIn[4], MemIType, MemISize[2];
- > char MemOut[4],MemOType, MemOSize[2];
- >};
-
- Why not do something "nasty" like this:
-
- #pragma pack(1) /* for MSC */
- #pragma option -a- /* for Borland C */
-
- Since you're defining an extreamly OS specific structure, you might
- as well use a compiler specific feature.
-
- Ross Ridge
-
- --
- Ross Ridge - The Great HTMU l/ //
- [OO][oo]
- ross@zooid.guild.org /()\/()/
- uunet.ca!zooid!ross db //
-