首页 > 其他分享 >stdarg

stdarg

时间:2024-03-11 12:33:06浏览次数:14  
标签:va printf Question will arg stdarg

stdarg

Question

  • How does va_arg (and so on) implemented?
  • What will happen if you call printf("%d", char)?

Answer

  • Question 1:
  • It is not implemented as a user program(not even in libc). It acts as if the C keyword sizeof. At compiling time, this word will be parsed by the compiler and do something to implement its funciton.
  • Question 2:
  • printf uses va_arg to get all the arguments. If you write %d, then it will assume that the argument is an integer(of type int). This may result in error because content is referenced by pointers.

标签:va,printf,Question,will,arg,stdarg
From: https://www.cnblogs.com/amazzzzzing/p/18065819

相关文章

  • stdarg.h头文件中va_arg的使用(关于类型获取)
    简介:此博客用于简单分析va_arg函数完成特定类型获取后指针移动的问题(针对int型参数i= -2,147,483,648获取后,指针偏移发生的错误)。 我在使用stdarg.h头文件模拟实现printf函数时遇见这样的情况:使用va_arg对函数可变参数进行特定类型获取后,va_arg函数再次读取时发生了关于......
  • 使用链表而不是 stdarg 实现可变参数函数
    Qidi2023.10.150.需要使用可变参数函数的场景常见的场景是类似于printf(char*fmt,...)函数,输入的参数个数和类型都是未知的,此时除了需要...表示可变参数列表,还需要用fmt参数说明参数的个数和类型。还有另一种场景,假设我们要实现一个音频控制功能的程序。在初始设计......
  • stdarg.h
    //定义char*指针类型#defineva_listchar*va_listap;char*ap;//指向可变参数的第一个#defineva_start(ap,last_arg)(ap=(va_list)&last_arg+sizeof(last......
  • C++学习---变长参数(stdarg.h)的实现原理
    引用C++中对stdarg.h头文件进行了封装,该头文件实现了函数变长参数,能够在定义函数时不必完全指定参数个数,而编译器能够在代码编译时,拿到所有的参数,并进行相应的处理。stdarg......