Messages in this thread | | | Subject | Re: [PATCH v5] printk: Userspace format enumeration support | From | Rasmus Villemoes <> | Date | Thu, 18 Mar 2021 12:31:44 +0100 |
| |
On 18/03/2021 11.46, Petr Mladek wrote:
> BTW: Is the trick with int (printk)(const char *s, ...) documented > somewhere? Is it portable?
It is completely standard and portable C, explicitly spelled out in the C standard itself. C99:
=== 6.10.3 Macro replacement
10 [...] Each subsequent instance of the function-like macro name followed by a ( as the next preprocessing token introduces the sequence of preprocessing tokens that is replaced by the replacement list in the definition (an invocation of the macro). [...] ===
and later
=== 7.1.4 Use of library functions
1 [...] one of the techniques shown below can be used to ensure the declaration is not affected by such a macro. Any macro definition of a function can be suppressed locally by enclosing the name of the function in parentheses, because the name is then not followed by the left parenthesis that indicates expansion of a macro function name. For the same syntactic reason, it is permitted to take the address of a library function even if it is also defined as a macro. ===
Also, the use of printk() inside the definition of a printk() function-like macro does not lead to infinite recursion, by
=== 6.10.3.4 Rescanning and further replacement
2 If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file’s preprocessing tokens), it is not replaced. ===
Rasmus
| |