delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/06/06:19:56

From: Robert Hoehne <Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: GCC/Info docs bug regarding __attribute__
Date: Fri, 01 Aug 1997 12:53:05 +0200
Organization: TU Chemnitz-Zwickau
Lines: 45
Message-ID: <33E1C011.4A51DB09@Mathematik.TU-Chemnitz.DE>
References: <5rrni2$48j AT freenet-news DOT carleton DOT ca>
NNTP-Posting-Host: prokyon.hrz.tu-chemnitz.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Paul Derbyshire wrote:
> 
> In a program I am writing I am having problems using __attribute__ ((packed))
> on a struct meant for reading the (unpacked) records of a binary file

DJGPP comes with a very good example of how to use this attribute.
Look at the include/dos.h file how the struct _fint_t is declared.

BTW: There you can see, that you have to "pack" each element of the
struct and not only the struct at once.

> I am forced to conclude one of three things is the case:


Here my guess about your problem:

You are using it in a C++ file?? (please include that information
in the furure, because C and C++ are sometimes different to program).

The description in the gcc docs are valid only for C and not for C++.
(I tried it now).

Here is the syntax, which can be used in both languages

typedef struct
{
  char dummy2
  char dummy2;
} foo __attribute__ ((packed));

But as said above this will not solve you problem, because
you have to pack EACH member of the struct.


BTW: All the above is nowhere written, I found it only
by trying it many times ago.

Robert
-- 
*****************************************************************
* Robert Hoehne, Fakultaet fuer Mathematik, TU-Chemnitz-Zwickau *
* Post:    Am Berg 3, D-09573 Dittmannsdorf                     *
* e-Mail:  Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE              *
* WWW:     http://www.tu-chemnitz.de/~rho                       *
*****************************************************************

- Raw text -


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