www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/05/01/13:56:35

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Sat, 01 May 2004 20:56:08 +0200
From: "Eli Zaretskii" <eliz AT gnu DOT org>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp-workers AT delorie DOT com
Message-Id: <8011-Sat01May2004205607+0300-eliz@gnu.org>
X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 1.8.9
Subject: pragma pack in dir.h
Reply-To: djgpp-workers AT delorie DOT com

This one cost me a few hours of debugging.

<dir.h> has this:

   /* This is for g++ 2.7.2 and below */
   #pragma pack(1)

   struct ffblk {
     char lfn_magic[6] __attribute__((packed));			/* LFN */
     short lfn_handle __attribute__((packed));			/* LFN */
     unsigned short lfn_ctime __attribute__((packed));		/* LFN */
     unsigned short lfn_cdate __attribute__((packed));		/* LFN */
     unsigned short lfn_atime __attribute__((packed));		/* LFN */
   ...

and later it does this:

   #pragma pack(4)

I suppose #pragma pack(4) was meant to return to the default struct
padding, but, at least with GCC 3.3.3, it doesn't.  This caused a
structure whose definition I reproduce below to have the offset for
the bit-field member enabled_p to be different from the offset of that
member in other source files, where dir.h was not included.  The
result was a subtle bug in the DJGPP port of Emacs, whereby
mouse-sensitive portions of the display stopped producing the desired
effect (display help-echo text in the echo area).

This whole pragma business is for GCC 2.7.2 and below, so one
possible solution is to condition the pragmas on those versions.

Alternatively, we could use "#pragma pack(0)", as this is documented
to reset the packing to the default, but I'm afraid that old versions
of GCC might not support that (otherwise, why didn't we use pack(0) in
the first place?).

Comments?

Here's the structure that gave me trouble with pack(4):

    struct glyph_row
    {
      struct glyph *glyphs[1 + LAST_AREA];
      short used[LAST_AREA];
      int x, y;
      int pixel_width;
      int ascent, height;
      int phys_ascent, phys_height;
      int visible_height;
      unsigned hash;
      struct display_pos start;
      struct display_pos end;
      unsigned left_user_fringe_bitmap : 8;
      unsigned left_user_fringe_face_id : 21;
      unsigned right_user_fringe_bitmap : 8;
      unsigned right_user_fringe_face_id : 21;
      unsigned left_fringe_bitmap : 8;
      unsigned left_fringe_face_id : 21;
      unsigned right_fringe_bitmap : 8;
      unsigned right_fringe_face_id : 21;
      unsigned redraw_fringe_bitmaps_p : 1;
      unsigned enabled_p : 1;
      unsigned truncated_on_left_p : 1;
      unsigned truncated_on_right_p : 1;
      unsigned overlay_arrow_p : 1;
      unsigned continued_p : 1;
      unsigned displays_text_p : 1;
      unsigned ends_at_zv_p : 1;
      unsigned fill_line_p : 1;
      unsigned indicate_empty_line_p : 1;
      unsigned contains_overlapping_glyphs_p : 1;
      unsigned full_width_p : 1;
      unsigned mode_line_p : 1;
      unsigned overlapped_p : 1;
      unsigned ends_in_middle_of_char_p : 1;
      unsigned starts_in_middle_of_char_p : 1;
      unsigned overlapping_p : 1;
      unsigned mouse_face_p : 1;
      unsigned ends_in_newline_from_string_p : 1;
      unsigned exact_window_width_line_p : 1;
      unsigned cursor_in_fringe_p : 1;
      unsigned indicate_bob_p : 1;
      unsigned indicate_top_line_p : 1;
      unsigned indicate_eob_p : 1;
      unsigned indicate_bottom_line_p : 1;
      int continuation_lines_width;
    };

- Raw text -


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