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

From: Bela Lubkin <belal_at_sco.COM>
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 majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Thu May 01 1997 - 00:51:24 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:38:00 BST