See the macro'ized version. I use #define to define very temporary helpers, then #undef to undefine them so I can use the macro with multiple types and still use the same #define names.
It would be nifty (although, I'm not sure if essential) if #macros had the concept of scope, and #tempdef's were automatically #undef'd at the end of the macro. Maybe something more macro-frenzied like fb-ext could make use of it?
I wonder if this would complicate the detection of recursive macro calls... say, if #tempdef could somehow allow more powerful preprocessing depending on how scope is implemented. (Ex: Nested macro calls.) What would it take to make our preprocessor Turing-complete? :)
I want to turn this:
Code: Select all
#macro MakeGlobalStackOf(T)
#define GlobalStackOfName GlobalStackOf##T
#define global_stack_array_name global_stack_array_of_##T
type GlobalStackOfName
...
end type
sub GlobalStackOfName.push( byref value as T )
global_stack_array_name( index ) = value
end sub
#undef GlobalStackOfName
#undef global_stack_array_name
#endmacro
Code: Select all
#macro MakeGlobalStackOf(T)
#tempdef GlobalStackOfName GlobalStackOf##T
#tempdef global_stack_array_name global_stack_array_of_##T
type GlobalStackOfName
...
end type
sub GlobalStackOfName.push( byref value as T )
global_stack_array_name( index ) = value
end sub
#endmacro