This __attribute__ allows assigning printf-like or scanf-like characteristics to the declared function, and this enables the compiler to check the format string against the parameters provided throughout the code. This is exceptionally helpful in tracking down hard-to-find bugs.
There are two flavors:
-
__attribute__((format(printf,m,n)))
-
__attribute__((format(scanf,m,n)))
but in practice we use the first one much more often.
The (m) is the number of the "format string" parameter, and (n) is the number of the first variadic parameter. To see some examples:
/* like printf() but to standard error only */
extern void eprintf(const char *format, ...)
__attribute__((format(printf, 1, 2))); /* 1=format 2=params */
/* printf only if debugging is at the desired level */
extern void dprintf(int dlevel, const char *format, ...)
__attribute__((format(printf, 2, 3))); /* 2=format 3=params */
With the functions so declared, the compiler will examine the argument lists
$ cat test.c
1 extern void eprintf(const char *format, ...)
2 __attribute__((format(printf, 1, 2)));
3
4 void foo()
5 {
6 eprintf("s=%s\n", 5); /* error on this line */
7
8 eprintf("n=%d,%d,%d\n", 1, 2); /* error on this line */
9 }
$ cc -Wall -c test.c
test.c: In function `foo':
test.c:6: warning: format argument is not a pointer (arg 2)
test.c:8: warning: too few arguments for format
Note that the "standard" library functions - printf and the like - are already understood by the compiler by default.
分享到:
相关推荐
hCom=CreateFile(name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL); if(INVALID_HANDLE_VALUE==hCom) { // errLog.Format("create com file faild,port...
ret = sysfs_create_group(&dev->pdev->dev.kobj, &vfe_attribute_group); #ifdef CONFIG_ES dev->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1; dev->early_suspend.suspend = vfe_early_suspend...
ret = sysfs_create_group(&dev->pdev->dev.kobj, &vfe_attribute_group); #ifdef CONFIG_ES dev->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1; dev->early_suspend.suspend = vfe_early_suspend...
Delphi 获取文件访问时间,也主是最后一次打开文件 的时间,... Result:=Format('%d年%d月%d日 %2.2d:%2.2d:%2.2d',[STime.wYear,STime.wMonth,STime.wDay,STime.wHour,STime.wMinute,STime.wSecond]); end; end;
validates :my_attribute , presence : true , codice_fiscale_format : true end 可用的验证器 codice_fiscale_format :意大利税码称为“ Codice Fiscale”。 有关更多信息,请参见 。 partita_iva_format :...
Opened database physical structure file format(XML standard format). Supply the source program of the outer invocation database, including these three edition: C#/Delphi/JAVA. 11.Support multi-...
NowTime = Format(Now, "yyyy-mm-dd_hh-mm-ss") backFile = "hotel" & NowTime sql = "BACKUP DATABASE hotel TO disk='" & App.Path & "\BackUP\" & backFile & "'" cn.Execute (sql) MsgBox "数据库备份成功!" & ...
format example strokeRadius dimension app:strokeRadius="5dp" strokeWidth dimension app:strokeWidth="2dp" textSize dimension app:textSize="16sp" selectedColor color/reference app:...
= u.attribute :created_at, format: :short %> <%= u.attribute :last_sign_in_at, if_blank: "User did not access yet", wrapper_html: { id: "sign_in_timestamp" } %> <%= u.attribute :photo...
getattr `getattr`函数属于内建函数,可以通过函数名称获取 复制代码 代码如下: value = obj.attribute value = getattr(obj, “attribute”) ...def output(data, format=”text”): output_function = getatt
javax.swing.text.rtf 提供一个类 (RTFEditorKit),用于创建富文本格式(Rich-Text-Format)的文本编辑器。 javax.swing.tree 提供处理 javax.swing.JTree 的类和接口。 javax.swing.undo 允许开发人员为应用程序...
如何设置存储位置要使用gcc将变量/结构放在某个内存位置,请执行以下操作: volatile mystruct_t __attribute((section (".fwConfigSection"))) mystruct = { 0 };并使用链接器注册该部分: LDFLAGS += -Wl,--...
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000 Private Const OPEN_EXISTING = 3 ' COMM Functions Private Const MS_CTS_ON = &H10& Private Const MS_DSR_ON = &H20& Private Const MS_RING_ON = &H40& ...
vhdl data typeSignal Attributes• Specific values associated with signals.• Format:signal_name attribute_designator
6) If your version of Delphi does not support text format DFM files (e.g. Delphi 4 doesn't), you will have to use the convert.exe utility supplied with Delphi to convert all the demo form files to ...
最近在cv做个博客,碰到了需求要弄个网站图标。... print('生成完毕,{} --> {}'.format(img_name, ico_name)) except (AttributeError, IOError): print("图片路径或尺寸选择错误") input("按任意键退出")
Git 2.33 Release Notes ====================== Updates since Git 2.32 ---------------------- UI, Workflows & Features * "git send-email" learned ... with __attribute__() to catch placeholder/parameter
VERSION 5.00 Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX" Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX" Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90...
data storage method is ARFF format (Section 2.4). You can easily conve. a spreadsheet to ARFF. The bulk of an ARFF file consists of a list of the ins and the attribute values for each instance are ...
Swift的C结构处理 在Swift中打包和解压缩C结构的类,以Python中的模块为模型。 样例代码 import MVPCStruct // Receiver expects a message with a header like this: // typedef struct { ...// } __attribute__