Google Answers Logo
View Question
 
Q: C preprocessor magic for definition and conditional compilation of functions ( No Answer,   1 Comment )
Question  
Subject: C preprocessor magic for definition and conditional compilation of functions
Category: Computers > Programming
Asked by: gnurou-ga
List Price: $5.00
Posted: 25 May 2005 14:41 PDT
Expires: 30 May 2005 05:12 PDT
Question ID: 525598
Hello experts,

I need to conditionate the compilation of functions in a C file by
macro definitions. I'll give an example of what I've been trying to
get, but I also accept any answer or suggestion that leads to the same
result, provided it works with the standard GNU compilation tools.

I have a set of C functions in a file, and I want to be able to
enable/disable their compilation by setting or not a macro. Here is a
short example:

#ifdef compile_A
void A()
{
  ...
}
#endif

#ifdef compile_B
void B()
{
  ..
}
#endif

However, in my case I'm manipulating very long function names. I'd
like to obtain the same effet by a set of preprocessor macros such as:

DEFINE_FUNCTION(A)
 ..
END_FUNCTION

DEFINE_FUNCTION(B)
 ..
END_FUNCTION

These macros would expand to the same output as above, or something
completely equivalent.

After digging through the cpp documentation, I have been unable to
find something that would do. I don't want to use any other layer of
preprocessing, so if someone would have a solution that works with the
standard GNU cpp, that'd be just great.

Request for Question Clarification by maniac-ga on 25 May 2005 16:38 PDT
Hello Gnurou,

Would you be willing to run the C preprocessor as an added step prior
to the C compiler?

The general solution to what you ask (nested evaluation of
preprocessor directives) is not possible in C (it was in Jovial, but
alas not C). [and I would explain why in a complete answer]

It would also be possible to automate that extra step using a
Makefile; I would explain that as well.

  --Maniac

Clarification of Question by gnurou-ga on 25 May 2005 23:07 PDT
It should be acceptable to run the preprocessor separately, although
I'd prefer not to generate intermediate files. But if there is no
other solution, I'll accept that too. Anyway, I'm already using a
Makefile. Please go ahead. :)
Answer  
There is no answer at this time.

Comments  
Subject: Re: C preprocessor magic for definition and conditional compilation of functions
From: bozo99-ga on 26 May 2005 14:32 PDT
 
It is common to run an ealier layer of pre-processing on s/w with autoconf.
Recall the many INSTALL files containing these steps where the
configure command sets the appropriate macro definitions in the
Makefile.

./configure
make
make test
make install

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy