[sane-devel] dc240 only works with GCC

Petter Reinholdtsen pere@hungry.com
Fri, 11 Oct 2002 18:50:14 +0200


I just discovered this code when trying to find out why the CVS
version of sane-backends fail to compile on HP/UX using the native
compiler.

  #ifdef __GNUC__
  #define UNUSEDARG __attribute__ ((unused))
  #define PACKED    __attribute__ ((packed))
  #else
  #define UNUSEDARG
  /* You need to figure out a way to ensure that there are no holes
   * in the following dir_buf structure - it has to match data read from
   * the camera.  gcc does this with __attribute__ ((packed))
   */
  #error
  #endif

First of all, '#error' need a parameter to be ANSI C.  But the real
problem is that '__attribute__((packed))' only work on GCC.  I suggest
that this backend only is compiled when using GCC.  The real fix would
be to rewrite this to be portable code.  I do not believe it is
possible to get packed structs any portable way.

Here is a patch to fix the typo and use the available PACKED macro.

Index: dc240.h
===================================================================
RCS file: /cvsroot/external/sane/sane-backends/backend/dc240.h,v
retrieving revision 1.2
diff -u -3 -p -u -w -r1.2 dc240.h
--- dc240.h     2002/09/22 13:49:47     1.2
+++ dc240.h     1994/10/11 16:48:31
@@ -212,14 +212,14 @@ struct cam_dirent
  * in the following dir_buf structure - it has to match data read from
  * the camera.  gcc does this with __attribute__ ((packed))
  */
-#error
+#  error "Please port to this compiler."
 #endif

 struct dir_buf
 {
   SANE_Byte entries_msb PACKED;
   SANE_Byte entries_lsb PACKED;
-  struct cam_dirent entry[1000] __attribute__ ((packed));
+  struct cam_dirent entry[1000] PACKED;
 };

 struct cam_dirlist