栈上分配内存: alloca()The alloca() function allocates size bytes of space in the stack frame of the caller. This temporary space is
automatically freed when the function that called alloca() returns to its caller.作用域extern也可以在函数声明中指定,唯一的影响是将该声明的隐式属性“在其它地方定义”变为显示。extern void putValue(int , int);register声明寄存器自动对象,适合函数中频繁被使用的自动变量,比如循环语句中的数组索引和指针;register对编译器来说只是一个建议,编译器使用寄存器分配算法找出最合适的候选放到机器可用的寄存器中。静态局部对象,static,它的值在函数调用之间保持有效,但其名字的可视性仍限制在其局部域内;在对象的声明处被首次初始化const指向const对象的指针: const double ptr;1. 其本身不是常量,可以重新赋值,使其指向不同的对象,但不能修改其指向的对象;2. 指向const对象的指针可以被赋以一个非const对象的地址;3. 常被用作函数的形式参数;const指针:int const ptr2 = #1. ptr2是指向非const对象的const指针,auto_ptrauto_ptr对象被初始化为指向由new表达式创建的动态分配对象,当auto_ptr对象的生命期结束时,动态分配的对象被自动释放。auto_ptr
迭代器、mutable、volatilestatic
#include
#elif defined(HAVE_IMLIB2_H)
#include
#elif defined(HAVE_CV_H)
#include
#include
#else
#endif#define GNUC_PRINTF(format_idx, arg_idx)http://www.gnu.org/software/libcdio/doxygen/types_8h.html告诉编译器format和args的位置void purple_debug(PurpleDebugLevel level, const char category,const char format, ...) G_GNUC_PRINTF(3, 4);
//----------------------------------------------------------------------------// G++链接GCC编译的目标文件//----------------------------------------------------------------------------如果C++程序需要使用C写的程序,则需要在C程序的头文件里面使用extern "C"将类型和函数声明封装起来#ifdef __cplusplus
extern "C" {
#endif/ declarations /#ifdef __cplusplus
}
#endif
//----------------------------------------------------------------------------// va_list//----------------------------------------------------------------------------[ Header ]
#include
[ 一般的用法 ]
va_list args; //声明变量
va_start(args, format); //开始解析, args指向format后面的参数
TYPE var = va_arg(args, TYPE); //取下一个参数并返回。args指向下一个参数
va_end(args); //结束解析
[ 例子 ]
1. long Slog::write( const int log2tty, const char *format, ... )
{
va_list args;
char msg[1024];
va_start(args, format);
vsnprintf(msg, 1024, format, args);
msg[1023] = 0; // ensure not overflow
va_end(args);
2. 求若干个整数的平均值
include
int AveInt(int,...);
void main()
{
printf("%d\t",AveInt(2,2,3));
printf("%d\t",AveInt(4,2,4,6,8));
return;
}
int AveInt(int num,...)
{
int ReturnValue=0;
int i = num;
va_list myvalist;
va_start(myvalist,num);
while(i>0)
{
ReturnValue += va_arg(myvalist,int);
i--;
}return ReturnValue/=num;
}
原文链接: https://www.cnblogs.com/edwardlost/archive/2010/10/16/1853211.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/16166
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!