# enable inside main () function

I would like to know if it is possible to main()include anything inside a function from C.

For example, in the Cell program, I define parameters for cache-api.h, which main()I want to change later in the function .

I realized that what was defined with the help #definecan be undefined from #undefanywhere in the program, but after overriding my required parameters, I have to turn on cache-api.h again. Is it possible?

How can I solve this problem more elegantly? Suppose I want to read from the main repository using cache_rd(...), but the types will be different at runtime of the SPU, how can I use both #define CACHED_TYPE struct xand #define CACHED_TYPE struct yin one program?

Thanks in advance for the answer, I hope that I understand the expression.

+3
source share
4 answers

#defineand #includeare pre-processor macros: http://en.wikipedia.org/wiki/C_preprocessor

They are converted / inserted before compilation.

To answer your question ... no, you really would not want to do this, at least for the next guy who should try to unleash this mess.

+1
source

#defineand #include- these are only text operations that occur during the preprocessing phase, which is a technically optional phase. That way, you can mix and match them in a variety of ways, and as long as your preprocessor syntax is correct, it will work.

, #undef, , .

typedef , , , , , #define .

+3

, ( , ), #include - , #include.

+2

#include . , ; , , .

, ( ) - . , likley .

, , , .

, , , .

One of the possible solutions to your problem is to create separately compiled modules (compilation units) containing wrapper functions, the API that needs to be called. Each compilation unit may then include an API header file after defining the appropriate configuration macros. After that, you will have two separate and independent interfaces provided by these wrapping functions.

0
source

All Articles