当前位置: C语言 -- 附录 -- abort_handler_s

abort_handler_s函数


概要:
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>
void abort_handler_s(
      const char * restrict msg,
      void * restrict ptr,
      errno_t error);

描述:

指向abort_handler_s函数的指针可用作set_constraint_handler_s函数的参数。

该函数以实现定义的格式向标准错误流(stderr)写入一条信息(该信息包含参数msg指向的字符串。);然后调用abort函数终止程序。


参数:
const char * restrict msg

指向描述运行约束冲突字符串的指针。

void * restrict ptr

空指针或者指向实现定义对象的指针。

errno_t error

如果调用运行约束处理程序的安全函数的返回类型是errno_t,参数error是安全函数的返回值;否则参数error为传递的errno_t类型的正值。


返回值:

该函数不会返回给调用者。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
/*安全函数abort_handler_s范例*/

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    set_constraint_handler_s(abort_handler_s);

    FILE *pFile;
    char *mode = NULL;
    fopen_s(&pFile, "gch.txt", mode);  //运行约束:mode不能为空指针。
    fclose(pFile);

    return 0;
}


结果:

注:测试时Visual Studio软件还未支持abort_handler_s函数,以上例子仅供参考。


相关内容:
set_constraint_handler_s 设置运行约束处理程序的安全函数。
ignore_handler_s 发生运行约束冲突时忽略运行约束冲突的安全函数。