set macro value depending on compilation parameters

Roberto Ostinelli <>
Sun Oct 25 01:25:40 CEST 2009


dear all,

i need to define a macro to expand differently depending on a macro
value passed at compilation time.

for instance, consider the following macro declared inside a module 'test':

-ifdef(foo).
-define(FCTN, true).
-endif.

now, what i would like is that if i compile the module 'test' like this:

1>c(test, {d, foo, bar}).
{ok, test}

then inside module 'foo' the macro ?FCTN expands to true [as per the
example above], while if i compile like this:

1>c(test, {d, foo, baz}).
{ok, test}

then inside module 'foo' the macro ?FCTN expands to false.

the way i'm currently using to achieve this is:

-ifdef(foo).
-define(FCTN, case ?foo of
	bar ->
		true;
	baz ->
		false
end).
-endif.

however, i do not want to have FCTN perform a case condition every
time it is called, since it will ALWAYS return one of the two options
once it is compiled. is erlc already optimizing this, ignoring the
case condition? or is there another [and better] way to achieve this
result?

thank you for any suggestions you may have.

cheers,

r.


More information about the erlang-questions mailing list