Subject: FVWM: Re: Compiling fvwm2 on SCO 5.0.2 - cpp problems

From: Bela Lubkin <[email-masked]>
Date: Wed, 30 Apr 1997 22:47:38 -0700

Maxwell Spangler wrote (moved from comp.unix.sco.misc):

> Users have suggested I look into c preprocessor macro expansion problems
> which we believe are causing at least part of my problem.
> 
> It appears as though the expanded macros have more spaces in them than
> the c compiler would like to see.
> 
> Here's a snippet from the original code, in add_window.c:
> 
> ----------------------------------------------------------------
> /* ORIGINAL CODE WHICH CAUSES SCO COMPILER TO PRODUCE AN ERROR
>   tmp_win->title_height = GetDecor(tmp_win,TitleHeight) + tmp_win->bw;
> */
> 
> /* THIS LINE, WHICH SHOULD BE EXPANED BY THE MACRO, COMPILES. */
>   tmp_win->title_height = ( ( tmp_win )->fl->TitleHeight ) +
> tmp_win->bw;
> ------------------------------------------------------------------
> 
> This is what cc -E add_window.c (with all other Makefile options like
> -DUSEDECOR added, also.)
> 
> # 227
>   tmp_win->title_height =  ( ( tmp_win ) -> fl ->TitleHeight ) + tmp_win
> -> bw ;
> 
> I'm guessing that with the extra spaces, the compiler doesn't recognize
> -> for pointers and is producing errors.  The above code is exactly this
> minus the spaces and seems to compile fine.

If you renamed your preprocessed add_window.i to junk.c, then did cc -c
junk.c, you would see that it compiled just fine.

> Here's the macro, unmodified:
> ---------------------------------------------------------------------
> /* FROM screen.h THE ORIGINAL MACRO CODE
>    Macro which gets specific decor or default decor.
>    This saves an indirection in case you don't want
>    the UseDecor mechanism.
>  */
> #ifdef USEDECOR     /* THIS IS WHAT i WANT TO USE */
> #define GetDecor(window,part) ((window)->fl->##part)
> #else
> #define GetDecor(window,part) (Scr.DefaultDecor.##part)
> #endif
> ------------------------------------------------------------------------

Here's the problem.  Those token-paste operators ("##") are wrong.  ANSI
C requires that in  a ## b, all three of "a", "b", and the resulting
pasted token, be valid preprocessor tokens.  "->TitleHeight" is not a
valid token (it's *two* valid tokens).  Token pasting is not wanted
here.  The macros should read:

  #ifdef USEDECOR     /* THIS IS WHAT i WANT TO USE */
  #define GetDecor(window,part) ((window)->fl->part)
  #else
  #define GetDecor(window,part) (Scr.DefaultDecor.part)
  #endif

The AT&T/USL/SCO compiler differs from gcc in this matter.  It is not
wrong.  gcc is interpreting the ANSI standard more loosely than SCO cc.

>Bela<

PS: it would have been easier to figure out if you had included the
    actual error message!  I got:

      "junk.c", line 6: error: invalid token: ->TitleHeight
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Andrew Veliath <[email-masked]>
Date: Thu, 1 May 1997 16:11:19 -0400

Bela> Here's the problem.  Those token-paste operators ("##") are
    Bela> wrong.  ANSI C requires that in a ## b, all three of "a",
    Bela> "b", and the resulting pasted token, be valid preprocessor
    Bela> tokens.  "->TitleHeight" is not a valid token (it's *two*
    Bela> valid tokens).  Token pasting is not wanted here.  The
    Bela> macros should read:

    Bela>   #ifdef USEDECOR /* THIS IS WHAT i WANT TO USE */ #define
    Bela> GetDecor(window,part) ((window)->fl->part) #else #define
    Bela> GetDecor(window,part) (Scr.DefaultDecor.part) #endif

    Bela> The AT&T/USL/SCO compiler differs from gcc in this matter.
    Bela> It is not wrong.  gcc is interpreting the ANSI standard more
    Bela> loosely than SCO cc.

Bela: thanks for this solution.  Sorry, this was my blunder.

Chuck: please make sure this change below gets into the next release.

Regards,
Andrew

--- screen.h.orig	Thu May  1 16:03:09 1997
+++ screen.h	Thu May  1 16:03:34 1997
@@ -329,9 +329,9 @@
    the UseDecor mechanism.
  */
 #ifdef USEDECOR
-#define GetDecor(window,part) ((window)->fl->##part)
+#define GetDecor(window,part) ((window)->fl->part)
 #else
-#define GetDecor(window,part) (Scr.DefaultDecor.##part)
+#define GetDecor(window,part) (Scr.DefaultDecor.part)
 #endif
 
 /* some protos for the decoration structures */