Re: cernlib, preprocessor, etc

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Mon Mar 05 2001 - 11:07:21 EST

  • Next message: Flemming Videbaek: "Re: cernlib, preprocessor, etc"

    Hi Konstantin, Djamel, et al, 
    
    On Mon, 5 Mar 2001 08:43:23 -0500
    Konstantin Olchanski <olchansk@ux1.phy.bnl.gov> wrote
    concerning ": Re: cernlib, preprocessor, etc":
    > 
    > > The other thing concerns the preprocessor. Some files (*.F) need to be
    > > preprocessed before being compiled. The rule to preprocess the *.F files
    > > is:
    > > 
    > > gcc -E -C -P -x c $(CPPFLAGS) $(D_SYMBOLS) -o $*.f $<
    > > 
    > 
    > I am curious why you are using the "C" driver (gcc) instead of
    > the "Fortran" driver (g77). I was under the impression that the g77
    > driver runs the source files through the C preprocessor by default.
    
    As Djamel pointed out, this is the line that is in the CVS repository! 
    
    Also, on files that end in ".F", ".fpp" or ".FPP" are preprocessed by
    g77/gcc. Files ending in anything else is passed directly to the
    compiler proper. One can force preprocessing with flag 
    "-x f77-cpp-input" 
    
    > > My version of gcc is 2.96 (according to Christian, this version is
    > > known to be buggy), this is the one that you get with redhat 7.
    > 
    > This is pure FUD. On RedHat 7.0 you have the choice of "gcc" (2.96) and
    > "kgcc" (egcs-1.1.2). Neither is a formal FSF/GNU GCC release and both
    > are known to have bugs. Use whatever works for you, but note that
    > in language support, gcc-2.96 is closer to the ultimate gcc 3.0
    > than egcs-1.1.2. Also 2.96 is newer and has more bugs fixed than introduced.
    >
    > P.S. But wait! The C preprocessor was rewritten between
    > gcc 2.95 and 2.96-RH! Maybe they broke it for Fortran?
    
    Well, I guess it wasn't pure FUD(*). 
    
    I just did a small test, and this is what I found: If I any of execute 
    
      gcc -E foo.F 
      g77 -E foo.F 
    
    I use the preprocesor in 
      /usr/lib/gcc-lib/i386-redhat-linux/2.96/tradcpp0 -lang-fortran 
    But if I do either of 
    
      gcc -E -x c foo.F
      g77 -E -x c foo.F 
    
    I use 
      /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c 
    In the later case, labeled lines are screwed up. Now, to confirm
    Konstantin and my suspession that the preprocessor is to blame I did 
    
      gcc -E -x c -traditional foo.F  
      g77 -E -x c -traditional foo.F  
    
    and everything is fine since, again, the preprocessor is 
      /usr/lib/gcc-lib/i386-redhat-linux/2.96/tradcpp0 -lang-c 
     
    Conclussion: CPP of GCC 2.96 doesn't behave nicely (read: has a bug)
    if the user is careless enough to try to preprocess Fortran code as if
    it was C code. Now why anyone would want to preprosses Fortran code as
    if it was C code, is beyond me, but there may be a reason which is
    what Djamel wanted to know.  
    
    > I used both compilers to compile quite a bit of antique Fortran code
    > and did not really notice any difference between them.
    
    Probably not for the un-preproced source files, and you probably
    didn't have "-x c" which I see no reason for in the first place. 
    
    > > 
    > > My question is then: do we really need the option -x c for the
    > > preprocessing ? So far there wasn't any problem but with redhat 7, that's
    > > not the case.
    > > 
    
    I suggest, if no one complains, that you make the change from 
    
      gcc -E -C -P -x c ... 
    
    to 
    
      $(CPP) -E -P ... 
    
    where $(CPP) is defined according to compiler suit chosen: 
    
       ifeq ($(BRAHMS_ARCH),linux)
       FFLAGS          += -c
       CC              = gcc
       CFLAGS          = -c
       ifeq ($(FORTRAN_COMPILER),G77)
       CPP             = g77 -E 
       CPPFLAGS        = -DG77 $(patsubst %,-I%,$(INCDIRS))
       D_SYMBOLS       = -DG77
       FFLAGS          += -c -fno-automatic -ffixed-line-length-132 \
                            -fno-second-underscore -fugly-complex
       else
       CPP             = gcc -E -x f77-cpp-input
       CPPFLAGS        = -DPGF77 $(patsubst %,-I%,$(INCDIRS))
       D_SYMBOLS       = -DPGF77
       endif
       endif
    
    > I'll have to write a test case for this. Bear with me... But could you
    > try the "g77" driver first?
    
    Gives same results as gcc if you use the option "-x c". The point of
    not using g77 for preprocessing is that, at time, the Portland Fortran
    compiler was the compiler for BRAHMS, and I believe it doesn't come
    with a preprocessor, hence use the system one: gcc!
    
    (*) For those of you not familiar with this jargon(**), see 
    
        http://www.tuxedo.org/~esr/jargon/html/entry/FUD.html
    
    (**) The jargon used by Konstantin, me, and others on this list may
      not always be known to every one. There is an excellent lexicon
      on "Computer Geek Jargon" (sorry guys) at: 
    
        http://www.tuxedo.org/~esr/jargon/html/
     
      You can find a mirror site closer to your self at 
    
        http://www.tuxedo.org/~esr/jargon/alternates.html
    
      And you can find alternate formats at 
    
        http://www.tuxedo.org/~esr/jargon/download.html
    
      There's probaly also an RPM package out there somewhere. 
      I should stress that this is a must if you want to spend a good deal
      of time in front of the computer ROTFL (Rolling On The Floor
      Laughing - eh, not in the jargon file), and if you never understood
      the RTFM!
    
    Yours, 
    
    Christian  -----------------------------------------------------------
    Holm Christensen                             Phone:  (+45) 35 35 96 91 
      Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
      DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
      Denmark                                    Email:       cholm@nbi.dk
    



    This archive was generated by hypermail 2b29 : Mon Mar 05 2001 - 11:08:30 EST