LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1161|回复: 4

有没有编译器支持标准 C 的扩展特性的?

[复制链接]
发表于 2005-12-9 20:53:48 | 显示全部楼层 |阅读模式
就是说,哪个编译器能成功编译下面的程序?
  1. #define        __STDC_WANT_SECURE_LIB__        1
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdarg.h>

  5. void ereport(errno_t ec, char *fmt, ...)
  6. {
  7.         char es[100];        /* length must be greater than string literal below */
  8.         rsize_t n = sizeof es / sizeof es[0];
  9.         va_list v;

  10.         if (ec) {
  11.                 errno_t ec1 = strerror_s(es, n, ec);
  12.                 if (ec1)
  13.                         strcpy(es, "(cannot generate error message)");
  14.         }
  15.         va_start(v, fmt);
  16.         vfprintf(stderr, fmt, v);
  17.         va_end(v);
  18.         if (ec)
  19.                 fprintf(stderr, ": %s\n", es);
  20.         else
  21.                 fprintf(stderr, "\n");
  22. }

  23. int main(int argc, char *argv[])
  24. {
  25.         FILE *fp;
  26.         int c;
  27.         errno_t ec;

  28.         if (ec = fopen_s(&fp, argv[1], "r"))
  29.                 ereport(ec, "%s: cannot open %s", argv[0], argv[1]);
  30.         while ((c = fgetc(fp)) != EOF)
  31.                 putchar(c);
  32.         fclose(fp);
  33.         return 0;
  34. }
复制代码

我试了好多编译器都没法编译通过,是不是这个标准还是草案啊?
 楼主| 发表于 2005-12-9 21:01:19 | 显示全部楼层
标准在这儿:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2005-12-9 21:51:27 | 显示全部楼层
看起来像是草案(Draft TR),不过似乎必然进入C0x标准了。
Warning
This document is an ISO/IEC [color="Red"]draft Technical Report. It is not an ISO/IEC International Technical Report. It is distributed for review and comment. It is subject to change without notice and shall not be referred to as an International Technical Report or International Standard.
Recipients of this draft are invited to submit, with their comments, notification of any relevant patent rights of which they are aware and to provide supporting documentation.

不过C标准库里那些带_s后缀的visual c++ 2005(vc8)实现了。你可以试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-12-9 22:03:21 | 显示全部楼层
哎呀,我已经好几年没用过 VC 了,没处试啊
谁能帮我试试?谢谢。
回复 支持 反对

使用道具 举报

发表于 2005-12-10 14:04:59 | 显示全部楼层
  1. ------ Rebuild All started: Project: test1, Configuration: Debug Win32 ------
  2. Deleting intermediate and output files for project 'test1', configuration 'Debug|Win32'
  3. Compiling...
  4. main.cpp
  5. e:\work\vs\test1\main.cpp(15) : warning C4996: 'strcpy' was declared deprecated
  6.         d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
  7.         Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
  8. Compiling manifest to resources...
  9. Linking...
  10. LINK : E:\work\vs\test1\Debug\test1.exe not found or not built by the last incremental link; performing full link
  11. Embedding manifest...
  12. Build log was saved at "file://e:\work\vs\test1\test1\Debug\BuildLog.htm"
  13. test1 - 0 error(s), 1 warning(s)
  14. ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
复制代码
VS 2005
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表