Chinaunix

标题: c11 宏重载的问题 各位伸把手帮一把 [打印本页]

作者: 79hy    时间: 2013-10-09 11:08
标题: c11 宏重载的问题 各位伸把手帮一把
最近骚,想试试c11, 我是centos6.3 gcc原先好像是4.4.7,我升级到4.8.1了。

编译总出现问题。在网上转了一大圈,没有找到解决方法。  各位有碰到过的吗?还是我的路子就走错了?????

编译  gcc -std=c11 b.c

报错如下:
  1. b.c: In function ‘main’:
  2. b.c:22:5: warning: implicit declaration of function ‘_Generic’ [-Wimplicit-function-declaration]
  3.      put (123);
  4.      ^
  5. b.c:4:30: error: expected expression before ‘float’
  6. #define put(x) _Generic((x), float: put_float, int: put_int)(x)
  7.                               ^
  8. b.c:22:5: note: in expansion of macro ‘put’
  9.      put (123);
  10.      ^
  11. b.c:4:30: error: expected expression before ‘float’
  12. #define put(x) _Generic((x), float: put_float, int: put_int)(x)
  13.                               ^
  14. b.c:23:5: note: in expansion of macro ‘put’
  15.      put (1.2f);
  16.      ^
复制代码
  1. #include <stdio.h>



  2. 代码是这个
  3. #define put(x) _Generic((x), float: put_float, int: put_int)(x)


  4. void put_float (float x)
  5. {
  6.     printf ("%f\n", x);
  7. }

  8. void put_int (int x)
  9. {
  10.     printf ("%d\n", x);
  11. }

  12. int
  13. main (void)
  14. {
  15.     //put_int (123);
  16.     //put_float (1.2f);
  17.     put (123);
  18.     put (1.2f);
  19.     return 0;
  20. }
复制代码

作者: 79hy    时间: 2013-10-10 10:26
2天没人回复。编了3个小时,编了个clang, 还是clang牛B。过了。
作者: bruceteen    时间: 2013-10-10 10:55
google呀,http://www.cnblogs.com/zenny-chen/p/3303560.html
作者: kandia    时间: 2013-10-10 10:56
GCC目前还不支持_Generic
http://gcc.gnu.org/wiki/C11Status

Clang已经完全实现C11/C++11
作者: myworkstation    时间: 2013-10-10 11:14
回复 1# 79hy


    gcc还不支持C11 generic selection,这儿有个支持的进展状态列表:http://gcc.gnu.org/wiki/C11Status
作者: 79hy    时间: 2013-10-10 11:44
回复 5# myworkstation


    非常感谢。clang支持_Generic 但是不支持threads.h 很期待,但是不能用。md
作者: myworkstation    时间: 2013-10-10 16:57
回复 6# 79hy


    clang支持的c11特性也是有限的。在这儿都列出来了:http://clang.llvm.org/docs/LanguageExtensions.html#c11
作者: 79hy    时间: 2013-10-14 16:12
非常感谢各位。再等等,看明年了。哈哈




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2