[erlang-questions] -include with define macro
zxq9
zxq9@REDACTED
Tue Sep 22 02:18:49 CEST 2015
On 2015年9月21日 月曜日 17:36:18 you wrote:
> On Mon, Sep 21, 2015 at 1:56 PM, zxq9 <zxq9@REDACTED> wrote:
>
> > On 2015年9月21日 月曜日 14:26:35 Martin Koroudjiev wrote:
> > > -ifdef(CONTAINING_APP_INCLUDE).
> > > -include(?CONTAINING_APP_INCLUDE).
> > > -endif.
> > >
> > > and to compile the source files as:
> > >
> > > erlc -Werror -Wall -DCONTAINING_APP_INCLUDE="\"<path>/<file>.hrl\""
> > > <module>.erl
> > >
> > > but I get the following error:
> > >
> > > badly formed 'include'
> >
> > I think includes run before macros, so your include is trying to include a
> > very odd-looking thing that starts with a question-mark instead of a
> > filename.
> >
>
> Not quite. The -include and -include_lib directives require that the thing
> between the parentheses is a string literal, so the tokens '?'
> 'CONTAINING_APP_INCLUDE'
> are not even subject to macro expansion in this case. (This could probably
> be easily fixed, if it is important to anyone.)
This would certainly make macros more flexible for Martin's purpose and be more in the spirit of how one expects macros to work (coming from C, anyway).
I think it wouldn't just be an issue of allowing macros in addition to string literals, though. It would require an extra pass to determine what includes are macro expansions, expand them, then perform the includes. After that continue on with normal macro expansion over the assembled source (included files often contain macros themselves).
Not that this is difficult to do, but it is slightly more work than just allowing other tokens to appear in -include and -include_lib.
-Craig
More information about the erlang-questions
mailing list