Macros may call themselves recursively (as long as they terminate). The following example shows how we can use a macro to calculate factorial at compile time. This example makes use of strong typing on both the argument and return type.
Before translation | After translation |
---|---|
|
|
Now consider that the return type on the factorial macro isn’t specified:
Before translation | After translation |
---|---|
|
|
If we don’t strongly type the argument then we end up with an erroneous definition because of lack of bracketing:
Before translation | After translation |
---|---|
|
|