www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/09/12:01:31

Xref: news2.mv.net comp.os.msdos.djgpp:5773
From: lehmann AT mathematik DOT th-darmstadt DOT de (Alexander Lehmann)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: C/C++ Packing (was: Re: [_dos_]find{first|next} problem!)
Date: 9 Jul 1996 12:24:01 GMT
Organization: Technische Hochschule Darmstadt
Lines: 51
Message-ID: <4rtj11$13n1@rs18.hrz.th-darmstadt.de>
References: <836767569 DOT 26385 DOT 0 AT abwillms DOT demon DOT co DOT uk> <31e1ed3d DOT 40380323 AT news DOT mcs DOT net>
NNTP-Posting-Host: fb0401.mathematik.th-darmstadt.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Peter Johnson (locke AT mcs DOT net) wrote:
: On Sun, 07 Jul 1996 19:27:32 GMT, alaric AT abwillms DOT demon DOT co DOT uk (Alaric
: B. Williams) wrote:

: >
: >It seems to be a structure packing problem... the ff.c in djtst claims
: >that the offset of ff_name is 30; but the SAME test in my code returns
: >32. Why is the packing changing? I compile both sources with the same
: >command line!
: >
: >Further examination shows that the fact that my file is a .cc and the
: >ff.c file is a .c matters. Why does the packing change????? they both
: >use the same include file dir.h, which lists the struct as being fully
: >packed!
: Here is what I found after copying the ff.c file to ff2.cc in the
: /tests/libc/dos directory, and compiling both (one as c, one as c++):
: Output of compiled ff.c:
: sizeof(ff) = 290
: ff.ff_attrib = 21
: ff.ff_ftime = 22
: ff.ff_fdate = 24
: ff.ff_fsize = 26
: ff.ff_name = 30
: (null): error

: Output of compiled ff.cc (identical to ff.c):
: sizeof(ff) = 292
: ff.ff_attrib = 21
: ff.ff_ftime = 22
: ff.ff_fdate = 24
: ff.ff_fsize = 28
: ff.ff_name = 32
: (null): error

: For some reason, ff_fdate is not packed as a SHORT!!  instead it is
: packed on a 4-byte margin...... HMMM!

This is a known bug in gcc 2.7.2, in C++, structures cannot be packed
like in C. To fix this, either wait for the next gcc, write wrapper
findxxx functions in a C module and call them from C++, or you can add
a #pragma statment that I current don't remember. You could check the
archive of comp.os.msdos.djgpp at http://www.delorie.com


bye, Alexander

--
Alexander Lehmann,                                  |  "On the Internet,
alex AT hal DOT rhein-main DOT de  (plain, MIME, NeXT)         |   nobody knows
lehmann AT mathematik DOT th-darmstadt DOT de (plain)          |   you're a dog."
!!CHANGED!! <URL:http://www.mathematik.th-darmstadt.de/~lehmann/>

- Raw text -


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