Skip to content

Instantly share code, notes, and snippets.

@cwsmith
Created October 6, 2012 19:05
Show Gist options
  • Save cwsmith/3845810 to your computer and use it in GitHub Desktop.
Save cwsmith/3845810 to your computer and use it in GitHub Desktop.
macro calling fn
mis.h
==================
#define PARMA_MAJOR_VERSION 1
#define PARMA_MINOR_VERSION 0
#define PARMA_PATCH_VERSION 170:177M
void mis_init(int randNumSeed, const char* maj, const char* min, const char* patch);
//#define misInit(seed) printf("misInit: %d\n", seed)
#define misInit(seed) mis_init(seed, PARMA_MAJOR_VERSION, PARMA_MINOR_VERSION, PARMA_PATCH_VERSION)
mis.cc
==================
void mis_init(int randNumSeed, const char* maj, const char* min, const char* patch) {
char msg[256];
sprintf("ParMA version %s.%s.%s\n", maj, min, patch);
statusPrint(msg);
seedRandomNumberGenerator(randNumSeed);
}
testMIS.cc
======================
int main() {
misInit(5); // fails
}
compile output
=========================
/users/cwsmith/develop/tools/openmpi/openmpi-1.4.3-install/bin/mpicxx -DHAVE_CONFIG_H -I. -I/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma -I./config -DPARALLEL -DFMDB_PARALLEL -DFMDB -D_HAVE_PARMETIS_ -D_HAVE_ZOLTAN_ -I/users/cwsmith/develop/ParMA/parma_build/include/ -I/users/cwsmith/develop/ParMA/parma_build/include -I/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/siter/src -I/users/cwsmith/develop/ParMA/parma_build/include -I/users/cwsmith/develop/ParMA/zoltan/Zoltan_v3.6-install//include/ -I/users/cwsmith/develop/ParMA/parmetis/ParMetis-3.1.1/ -I/users/cwsmith/develop/tools/petsc-3.2-p5-install/include -I/users/cwsmith/develop/tools/petsc-3.2-p5-install//include -I/users/cwsmith/develop/ParMA/parma_build/include -I/users/cwsmith/develop/tools/openmpi/openmpi-1.4.3-install/include -I/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/src -I/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet -g -O0 -MT maximalIndependentSet/test/testMIS.o -MD -MP -MF $depbase.Tpo -c -o maximalIndependentSet/test/testMIS.o /users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc &&\
mv -f $depbase.Tpo $depbase.Po
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(452): error: expected a ")"
misInit(randNumSeed);
^
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(452): error: argument of type "int" is incompatible with parameter of type "const char *"
misInit(randNumSeed);
^
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(452): error: argument of type "int" is incompatible with parameter of type "const char *"
misInit(randNumSeed);
^
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(454): error: expected a ")"
misInit(time(NULL));
^
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(454): error: argument of type "int" is incompatible with parameter of type "const char *"
misInit(time(NULL));
^
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc(454): error: argument of type "int" is incompatible with parameter of type "const char *"
misInit(time(NULL));
^
compilation aborted for /users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/test/testMIS.cc (code 2)
make: *** [maximalIndependentSet/test/testMIS.o] Error 2
@ibaned
Copy link

ibaned commented Oct 6, 2012

define misInit(seed) mis_init(seed, #PARMA_MAJOR_VERSION, #PARMA_MINOR_VERSION, #PARMA_PATCH_VERSION)

@ibaned
Copy link

ibaned commented Oct 6, 2012

or maybe

define VER_STR "VER_NUM"

@cwsmith
Copy link
Author

cwsmith commented Oct 6, 2012

The first results in the compile error:
/users/cwsmith/develop/ParMA/parma_build/SCOREC_Software/parma/maximalIndependentSet/mis.h(72): error: expected a macro parameter name
#define misInit(seed) mis_init(seed, #PARMA_MAJOR_VERSION, #PARMA_MINOR_VERSION, #PARMA_PATCH_VERSION)

@ibaned
Copy link

ibaned commented Oct 6, 2012

to elaborate on option 2:

define SVN_MAJOR_VERSION 1

define PARMA_MAJOR_VERSION "SVN_MAJOR_VERSION"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment