From: "Andrew Davidson" Newsgroups: comp.os.msdos.djgpp Subject: How does DJGPP store its structs? Date: Wed, 31 Mar 1999 04:00:17 +0100 Organization: Customer of Planet Online Lines: 46 Message-ID: <7ds34s$mpf$1@news7.svr.pol.co.uk> NNTP-Posting-Host: modem-73.xenon.dialup.pol.co.uk X-Trace: news7.svr.pol.co.uk 922849244 23343 62.136.26.201 (31 Mar 1999 03:00:44 GMT) NNTP-Posting-Date: 31 Mar 1999 03:00:44 GMT X-Complaints-To: abuse AT theplanet DOT net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I need to create a rather complex structure but have, so far, been unable to achieve this. The structure looks like this: typedef struct { unsigned char callbyte; signed long offset; unsigned char retbyte; // various other longs/shorts/chars etc } scratch; This probably needs a little explaining. Callbyte (should be located at byte 0 of a scratch structure) contains the value 0xe8 (near 32bit call with offset - in machine code) and retbyte contains 0xc3 (return from near call in machine code). 'offset' is then written to within the C code forming a small section of self modifying code. This code is called by passing a pointer to the struct to a simple 1 line asm() 'call'. My problem is that, although I would expect callbyte, offset, and retbyte to occupy the first 6 bytes of memory, they appear to be each occupying 4 bytes for a total of 12 bytes of memory. The structure is used in the following way within my code... typedef struct { scratch *scratchmem; char *workmem; // various other longs/shorts.chars etc } mainstruct; mainstruct *mystruct; I malloc memory for mystruct, scratchmem, and workmem, and I set all appropriate variables. I've tested the structs and all stuff done from within C code works fine. Is this 12 byte thing the result of the way I'm trying to use the scratch struct (from within another struct) or just a limitation of djgpp? I have a feeling that djgpp might be trying to optimise the struct so is there any way I can dissable this optimisation while keeping all the other forms of optimisation available? Andrew