delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/28/08:19:05

Xref: news2.mv.net comp.os.msdos.djgpp:608
From: malcolm AT manawatu DOT gen DOT nz (Malcolm Taylor)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: aligment / based pointers
Date: Thu, 25 Jan 1996 06:35:36 GMT
Organization: Grafik Software
Lines: 72
Message-ID: <4e74he$976@news.manawatu.gen.nz>
References: <960118222321_100662 DOT 3563_EHV63-1 AT CompuServe DOT COM>
Reply-To: malcolm AT manawatu DOT gen DOT nz
NNTP-Posting-Host: malcolm.manawatu.gen.nz
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Fulco Bohle <100662 DOT 3563 AT compuserve DOT com> wrote:

>Hello,

>1. I am porting sources from Microsoft C to DGGPP-C. what I need is 2-bytes
>alignment for all structure elements.
>DJGPP uses a default 4-bytes alignment strategy. 

>Microsoft C uses a pragma for non standard alignment, for example

>#pragma pack(4)		/* initiates 4-bytes alignment */

>typedef struct
>	{
>	char	aap;		/* dutch for monkey */
>	int	noot;		/* dutch for nut */
>	} s_leesplankje;		/* this is how I learned to read */

>sizeof (s_leesplankje) = max( sizeof( char), 4) + sizeof( int)

>#pragma pack(2)		/* initiates 2-bytes alignment */

>typedef struct
>	{
>	char	aap;
>	int	noot;
>	} s_leesplankje;

>sizeof (s_leesplankje) = max( sizeof( char), 2) + sizeof( int)	

>How do I obtain the same results in DGGPP-C

Use the __attribute__ ((aligned(2))) on the structure (see the gcc
info files). This may not guarantee that the structure will align on
the 2 byte boundaries though. Another method would be this:

struct {
   char aap; __attribute__ ((packed))
   char dummy; __attribute__ ((packed))
   int noot; __attribute__ ((packed))
};

This packs the structure (taking up as little room as possible), and
the dummy char will give the desired 2byte alignment.
A word of warning. If using v2.0 beta4 and compiling c++ code, the
packed attribute will not work. The only fix for this is to use the c
compiler (or use the beta3 gcc2.6.3 as the bug is in the c++ compiler
of gcc2.7.1).

>2. Does DJGPP-C understand based pointers ?

What is a based pointer?

>3. What is the main difference between djgpp verion 1.12 and 2.0 ?

Basicly v2.0 was written to clean up djgpp. v2.0 is much more stable
when using interrupts. Programs compiled will work under DOS, OS/2,
Win3.11, Win NT and Win95 (and probably in dosemu on Linux as well).
The headers have been completely rewritten and are more clean,
function prototypes are where they are expected etc. There is also
support for pure ANSI compatibility. Also the compiler is now
'boot-strapping', ie it is possible to compile gcc and all the tools
without using turbo c or tasm.

If you want more info on this (I think I covered most of the points)
try looking at http://www.delorie.com/djgpp where there is some info
on v2.0.

>Fulco Bohle



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019