g++ error: Macro names must be identifiers.

This is a discussion on g++ error: Macro names must be identifiers. within the C++ Programming forums, part of the General Programming Boards category; Hi there, I am trying to compile a C program that I am working on into C++... the compiler version ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    35

    g++ error: Macro names must be identifiers.

    Hi there,
    I am trying to compile a C program that I am working on into C++...

    the compiler version I am using is:
    Code:
    gcc version 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)

    The compiler options I am using are:
    Code:
    CFLAGS = -p -pg -g -O3 \
             -Blib \
             -Iinclude -I/usr/local/dislin \
             -funroll-loops -finline-functions \
             -Wall -W -Werror -Wno-unused
    The code in question begins:
    Code:
          1 #ifndef 631G_H
          2 #define 631G_H
          3
          4 #define GTO_CORE        CS1_6[Z][0]*exp(-E1_6[Z][0]*dprod)\
          5                         +CS1_6[Z][1]*exp(-E1_6[Z][1]*dprod)\
          6                         +CS1_6[Z][2]*exp(-E1_6[Z][2]*dprod)\
          7                         +CS1_6[Z][3]*exp(-E1_6[Z][3]*dprod)\
          8                         +CS1_6[Z][4]*exp(-E1_6[Z][4]*dprod)\
          9                         +CS1_6[Z][5]*exp(-E1_6[Z][5]*dprod)
         10
         11 #define D2_GTO_CORE  12.0(E1_6[Z][0]*CS1_6[Z][0]*exp(-E1_6[Z][0]*dprod)\
         12                          +E1_6[Z][1]*CS1_6[Z][1]*exp(-E1_6[Z][1]*dprod)\
         13                          +E1_6[Z][2]*CS1_6[Z][2]*exp(-E1_6[Z][2]*dprod)\
         14                          +E1_6[Z][3]*CS1_6[Z][3]*exp(-E1_6[Z][3]*dprod)\
         15                          +E1_6[Z][4]*CS1_6[Z][4]*exp(-E1_6[Z][4]*dprod)\
         16                          +E1_6[Z][5]*CS1_6[Z][5]*exp(-E1_6[Z][5]*dprod))
         17
         18 #define VALENCE_S        CS2_3[Z][0]*exp(-E2_3[Z][0]*dprod)\
         19                         +CS2_3[Z][1]*exp(-E2_3[Z][1]*dprod)\
         20                         +CS2_3[Z][2]*exp(-E2_3[Z][2]*dprod)
         21
         22 #define D2_VALENCE_S     CS2_3[Z][0]*exp(-E2_3[Z][0]*dprod)*(-6.0*E2_3[Z][0]+4.0*E2_3[Z][0]*E2_3[Z][0]*dp     
         23                         +CS2_3[Z][1]*exp(-E2_3[Z][1]*dprod)*(-6.0*E2_3[Z][1]+4.0*E2_3[Z][1]*E2_3[Z][1]*dp     
         24                         +CS2_3[Z][2]*exp(-E2_3[Z][2]*dprod)*(-6.0*E2_3[Z][2]+4.0*E2_3[Z][2]*E2_3[Z][2]*dp     
         25
         26 #define VALENCE_XYZ     CP2_3[Z][0]*component*exp(-E2_3[Z][0]*dprod)+\
         27                         CP2_3[Z][1]*component*exp(-E2_3[Z][1]*dprod)+\
         28                         CP2_3[Z][2]*component*exp(-E2_3[Z][2]*dprod)
         29
         30 #define D2_VALENCE_XYZ  -4.0*((1.5*component+1.0-E2_3[Z][0]*factor)*E2_3[Z][0]*CP2_3[Z][0]*exp(-E2_3[Z][0     
         31                              +(1.5*component+1.0-E2_3[Z][1]*factor)*E2_3[Z][1]*CP2_3[Z][1]*exp(-E2_3[Z][1     
         32                              +(1.5*component+1.0-E2_3[Z][2]*factor)*E2_3[Z][2]*CP2_3[Z][2]*exp(-E2_3[Z][2     
         33
         34 #define EXTRAVAL_S      CS2_1[Z]*exp(-E2_1[Z]*dprod)
         35 #define D2_EXTRAVAL_S   CS2_1[Z]*exp(-E2_1[Z]*dprod)*(-6*E2_1[Z] + 4*E2_1[Z]*E2_1[Z]*dprod)
         36 #define EXTRAVAL_XYZ    CP2_1[Z]*exp(-E2_1[Z]*dprod)
         37 #define D2_EXTRAVAL_XYZ  -4.0*(1.5*component+1.0-E2_1[Z]*factor)*(E2_1[Z]*CP2_1[Z]*exp(-E2_1[Z]*dprod))
    (some of it got chopped off but that doesn't matter because I think it's something fundamentally un-C++ I am doing (yet which google won't seem to yield its secrets on) rather than something in my definitions themselves).

    and the error I am getting is:
    Code:
    In file included from chi.c:2:
    include/631G.h:1:9: macro names must be identifiers
    chi.c: In function `double chi(basis_function, evector)':
    chi.c:35: error: `EXTRAVAL_S' undeclared (first use this function)
    chi.c:35: error: (Each undeclared identifier is reported only once for each function it appears in.)
    chi.c:52: error: `VALENCE_S' undeclared (first use this function)
    chi.c:56: error: `VALENCE_XYZ' undeclared (first use this function)
    chi.c:70: error: `EXTRAVAL_XYZ' undeclared (first use this function)
    Can anyone help?
    I searched the forums already and no luck (I also searched google) - the closest I came was someone saying that what someone wanted to do wouldn't work because "macros names must be identifiers and ' isn't"

    so I'd be very greatful if one of you C++ gurus could help out a total C++ virgin get his C program working as a C++ program so he can benchmark them against each other

    james

    *edit*
    Bloody hell!!!!
    I am glad I posted this here because I just saw THIS!:
    Code:
    #define D2_GTO_CORE  12.0(E1_6[Z][0]*
    I left out the multiplication symbol after the 12.0...
    this I guess is one of the real and horrible dangers of macros.
    does anyone know how this might be interpreted by the C compiler??
    why didn't it complain?

    *edit*
    ARGH!!!!
    I just tried compiling with the C compiler (I renamed the C++ makefile I was using and replaced it with the original) AND I GOT THE SAME ERRORS!?
    *edit
    (never mind - a make clean fixed that )

    *edit
    well for some reason that fixed it and it compiled each of the object files.
    HOWEVER, now I just have 1056 lines of various other errors to deal with.
    joy joy joy
    Last edited by eccles; 01-15-2005 at 01:38 AM.
    VIM + gcc + beer... does life get any better?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > -p -pg -g -O3
    Profiling and optimising at the same time doesn't make much sense to me.
    Profiling adds extra code to the executable, which in itself will slow you down.

    Profile first, try and understand the results, make measured changes to the code and repeat.
    When your code looks optimal from a functional point of view (all functions being called the expected number of times), then you can try with various -O flags.

    Also, -O3 is NOT necessarily better than -O2 (or -O1 for that matter). Each is based on some "average program", which means each option could have a negative effect in your particular case.

    You might also consider whether you're using the best algorithms for the task at hand. Remember that no amount of optimisation will rescue a bubble sort, compared to what a quick sort can achieve.

    Personally, I think you're better off sticking to C for the time being. It sounds like your C code is far from being anything like robust enough to be compiled with C++. Unless your program takes weeks to run, spending weeks to get it working only to save a few hours of run-time (say) is not effort well spent.

    All those exp() calls are probably something to do with the time it takes. Tweaking the code into C++ isn't going to change that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    35
    Hi Salem!
    thank you *so* much for your helpful and constructive comments.
    There's no real reason for me to keep the profiling options in the makefile by default, since the number of times I have used the output with gprof are nothing like the number of times I run the program to check my speed process.

    Thankyou also for your perspective on optimization options - this is the sort of thing that you only find out by asking people who have really had lots of experience.

    So I'll try tweaking the code, and you're probably right about it not being worth it trying to port it to C++... it's probably just a way of procrastinating... no language will offer a magic bullet when the code itself isn't perfect yet... and when I don't have hard and fast reasons for expecting that changing the language would offer significant benefits!

    thanks for this new perspective
    VIM + gcc + beer... does life get any better?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 02:10 AM
  2. runtime function names
    By lruc in forum Tech Board
    Replies: 2
    Last Post: 10-11-2008, 10:51 AM
  3. reading folder names..how is it done ?
    By roalme00 in forum C++ Programming
    Replies: 8
    Last Post: 01-11-2008, 09:34 AM
  4. Opening files with korean file names
    By tek in forum C++ Programming
    Replies: 4
    Last Post: 08-28-2003, 10:22 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21