From: David B. <dav...@da...> - 2008-01-22 23:09:29
|
SWIG never runs the preprocessor inside %{ ... %} blocks. That's why you're not seeing anything there :-). -Dave On Jan 22, 2008, at 4:55 PM, David Piepgrass wrote: >> From: David Beazley <dav...@da...> >> >> So, don't ask me why, but I was sitting here thinking about the Swig >> macro preprocessor this morning and started wondering if I could >> actually write recursive functions in the preprocessor. Well, the >> answer seems to be yes. Check out some examples: >> >> %define FACTORIAL(N) >> #if N == 0 >> 1 >> #else >> (N)*FACTORIAL(N-1) >> #endif >> %enddef > > SWEET! I'll be delighted if I can think of a use for this! Eat that, > ordinary C preprocessor :P > > Only, for some reason it doesn't work in C code: > > %define FACTORIAL(N) > #if N == 0 > 1 > #else > (N)*FACTORIAL(N-1) > #endif > %enddef > %constant FOO = FACTORIAL(6); // OK > > %{ > FOO; // nothin' > FACTORIAL(6); > %} > > See that last part? The output is not preprocessed. > > And guess what kind of failure you get from.... > > %define RECURSIVE(N) > RECURSIVE(N+1) > %enddef > %constant UH_OH = RECURSIVE(0); > > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user |