Next: , Previous: , Up: Macros   [Contents][Index]


7.1 Outer macros

Outer macros provide a shorthand way of invoking macro definitions in the source language; they are not expanded by FWEB. Outer macros are defined by ‘@d’ (see ATd) or ‘@D’ (see ATD_). They may be placed in any definition part. FTANGLE collects them during phase 1; during phase 2, they are simply copied in order of their appearance to the beginning of the output file. This is most useful for C or C++ codes; it’s a quick way of typing ‘#define’ when the positioning of the ‘#define’ is unimportant.

As an example,

@c
@
@d YES 1
@d NO 0
@a
main()
{}

@
@d BUF_LEN 100
@a
...

The keyword into which the ‘@d’ is translated is language-dependent; it is controlled by the style-file parameter ‘outer_def’. See Miscellaneous params.

Outer macros can be undefined by ‘@u’. The translation is controlled by the style-file parameter ‘outer_undef’. See Miscellaneous params.

The default behavior, in which the outer macro definitions are just copied to the top of the output file, is fine for simple applications. However, often C programmers prefer to maintain their macro definitions in a header file such as test.h. One way of accomplishing this is to redirect FTANGLE’s output from the command line, as in ‘ftangle test -=test.h’, then use an ‘@O’ command immediately after the first ‘@a’ in the web file to open up test.c. A more complicated variant of this allows additional information to be placed into the header file, as in the following example:

@c
@* INTRO.
We assume command-line redirection into \.{test.h} (`\.{-=test.h}').

@d A 1 // This will go into \.{test.h}.

@a
@<Header material@>@; // Also goes into \.{test.h}.
@O test.c // Remaining unnamed sections go into \.{test.c}.

@ Header material may be defined as needed throughout the code, but
with this design it will all go into \.{test.h}.

@<Header material@>=

@<Includes@>@;
@<Typedefs@>@;
@<Global variables@>@;


Next: , Previous: , Up: Macros   [Contents][Index]