简体   繁体   中英

Allowing %n$ operand for custom printf

I have a custom implementation of printf which I use in my school projects. Wishing to have the same warnings that printf, I use __attribute__((format (printf ...)) . That works fine, but using -Wall -Wextra -Werror -std=c11 -pedantic-errors , I get the error ISO C does not support %n$ operand number formats on gcc 7.2.0. (My implementation support that format). On clang it does not shout a warning if I use std=c11 , but does with std=c99 .

Is that format part of the c11 specification (as clang behavior let me think) or only the Singe Unix Specification (that is what my man page says) ? If so, how can I use it ? In this page , I cannot find it as an option to std .

I would rather not disable any warnings, since they are quite useful and catches a lot. But is there a way to allow that format in format strings, or specify only for my function ?

Thanks a lot.

PS: I use a custom implemenation of printf because in my school projects we must only use specific allowed functions (basically, system api like malloc , free , read etc), or the one we have done ourselves.

EDIT : for reference, the format %n$ , with n being string of digit for a non-zero number, allow to access the argument at that index (starting at one) in the list of variable arguments given to printf. (And can be used for the conversion itself or for the precision or field widht with the * operand).

您可以在属性中使用gnu_printf而不是printf来模拟更接近POSIX的printf的行为。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM