提问人:Bishop 提问时间:8/11/2023 最后编辑:user16217248Bishop 更新时间:8/11/2023 访问量:102
在 C 语言中实现/定义的格式说明符在哪里?
Where are the format specifiers implemented/defined in the C language?
问:
我已经在 C 语言中工作了几个月,我从来没有想过要检查在 C 语言格式说明符中实际实现/定义的格式说明符的位置,例如:
%f
%d
%p
%s
#include <stdio.h>
int main(){
printf("%f",7.8);
}
我知道这些格式说明符是用来的,但我的问题是它们在 C 中在哪里实现/定义?stdio.h
答:
3赞
KamilCuk
8/11/2023
#1
格式说明符在哪里实现
它们是在您正在使用的特定实现源代码中实现的。有许多 prinf 的实现和 C 标准库的实现 - https://en.wikipedia.org/wiki/C_standard_library#Implementations。您正在使用其中之一。printf
有些更容易阅读 - https://github.com/eblot/newlib/blob/master/newlib/libc/stdio/vfprintf.c#L1220 .有些很难理解,并且已经优化了几十年 - https://github.com/lattera/glibc/blob/master/stdio-common/vfprintf.c#L293 .
用 C 语言定义?
printf
格式说明符在 C 语言标准中被“定义”——标准化、指定。我们在线使用的标准草案,您可以在此处阅读有关它们的信息 https://port70.net/~nsz/c/c11/n1570.html#7.21.6.1p1 .但是 cppreference https://en.cppreference.com/w/c/io/fprintf 比干标准更友好,格式也更好阅读。
评论
stdio.h
printf()
printf
scanf