英文:
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);
}
我知道这些格式说明符是用于与 stdio.h
一起使用的,但我的问题是它们在C语言中是在哪里实现/定义的?
英文:
I have been working in C for a couple months now and it has never come to my mind to check where actually the format specifiers implemented/defined in the C language format specifiers like:
%f
%d
%p
%s
#include <stdio.h>
int main(){
printf("%f",7.8);
}
I know these format specifiers are meant to be used with stdio.h
but my question is where are they implemented/defined in C?
答案1
得分: 3
他们是在您正在使用的printf
特定实现源代码中实现的。有许多printf
的实现和C标准库的实现 - https://en.wikipedia.org/wiki/C_standard_library#Implementations。您正在使用其中之一。
有些更容易阅读 - 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。
printf
格式说明符是在C语言标准中“定义”的 - 标准化,规定的。在线使用的标准草案中,您可以在此处阅读关于它们的信息https://port70.net/~nsz/c/c11/n1570.html#7.21.6.1p1。但是cppreference https://en.cppreference.com/w/c/io/fprintf更友好,格式更好,比干巴巴的标准更容易阅读。
英文:
> where are the format specifiers implemented
They are implemented in the specific implementation source code of printf
you are using. There are many implementations of prinf and implmentation of C standard library - https://en.wikipedia.org/wiki/C_standard_library#Implementations. You are using one of them.
Some are easier to read - https://github.com/eblot/newlib/blob/master/newlib/libc/stdio/vfprintf.c#L1220 . Some are very hard to comprehend and have been optimized through decades - https://github.com/lattera/glibc/blob/master/stdio-common/vfprintf.c#L293 .
> defined in the c language?
printf
format specifiers are "defined" - standardized, specified - in the C language standard. The draft of the standard we are using online you can read about them here https://port70.net/~nsz/c/c11/n1570.html#7.21.6.1p1 . But cppreference https://en.cppreference.com/w/c/io/fprintf is friendlier and much better formatted to read than dry standard.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论