This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

MS Style #pragma pack(push,...)


I'm compiling Microsoft C++ code (MFC, in fact)
for use with the Wine project under LINUX.

As has been discussed previously, the MFC code has a lot of
non standard extensions to the language.  The one I'm
fighting right now is their use of #pragma pack(push/pop,...).

gcc now handles this almost perfectly (see question #2, below),
but you have to #define HANDLE_PRAGMA_PACK_PUSH_POP in
order to enable this code.

Thus, in order for me to correctly compile this code, I either have
to build my own version of gcc or slash and burn through the code.

That's fine for me, but I'm trying to set up a set of directions
to make it simple for many more developers to be able
to repeat this process.

First, it seems to me that there is enough benefit to this process,
that it's worth making HANDLE_PRAGMA_PACK_PUSH_POP enabled
by default.  At the very least, couldn't we enable it as
a run time flag, so that developers wouldn't have to build
their own version of gcc to port Windows code with Wine?

Second, the pattern of #pragmas that MS uses is similar
to the following:

    #define _PACKNUM 4
    #pragma pack(push, _PACKNUM)

Currently, gcc treats that as a compiler error, because it doesn't
expand the macro in cccp.c.  I have revised cccp.c to solve
this error, as is attached.

Is this a reasonable change?    

Thanks,

Jeremy
diff -u old/cccp.c new/cccp.c
--- old/cccp.c	Tue Jun  1 12:10:01 1999
+++ new/cccp.c	Wed Jun 28 11:51:03 2000
@@ -3897,11 +3897,13 @@
 
       /* If a directive should be copied through, and -C was given,
 	 pass it through before removing comments.  */
+      /* #pragmas should not be copied through here, but in the
+      **   main preprocessing loop, which will allow macro expansion to occur
+      */
       if (!no_output && put_out_comments
 	  && ((kt->type == T_DEFINE || kt->type == T_UNDEF)
 	      ? dump_macros == dump_definitions
-	      : IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
-	      : kt->type == T_PRAGMA)) {
+	      : (IS_INCLUDE_DIRECTIVE_TYPE (kt->type) && dump_includes))) {
         int len;
 
 	/* Output directive name.  */
@@ -4043,10 +4045,13 @@
 	 just as if they were not defined.  And sometimes we're copying
 	 directives through.  */
 
+      /* #pragmas should not be copied through here, but in the
+      **   main preprocessing loop, which will allow macro expansion to occur
+      */
+
       if (!no_output && already_output == 0
 	  && (kt->type == T_DEFINE ? (int) dump_names <= (int) dump_macros
-	      : IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
-	      : kt->type == T_PRAGMA)) {
+	      : (IS_INCLUDE_DIRECTIVE_TYPE (kt->type) && dump_includes))) {
         int len;
 
 	/* Output directive name.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]