Posted to tcl by miguel at Fri Aug 03 20:08:04 GMT 2007view raw

  1. #include <stdio.h>
  2. typedef struct st {int poo;} st;
  3.  
  4. #define foo(x) ({st *v; v = moo(x); v == NULL ? 0 : v->poo; })
  5.  
  6. st * moo(st *x) {
  7. return x;
  8. }
  9.  
  10. int main(int argc, char *argv[]) {
  11. st x = {3}, *y = NULL;
  12. int j = foo(&x);
  13. int k = foo(y);
  14. fprintf(stderr, "j:%d, k:%d\n", j, k);
  15. }
  16.  

Comments

Posted by patthoyts at Fri Aug 03 20:11:07 GMT 2007 [text] [code]

C:\temp\func>cl -W3 -Zi -MD miguel.c -link -subsystem:console -debug Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. miguel.c miguel.c(12) : error C2059: syntax error : '{' miguel.c(12) : error C2065: 'v' : undeclared identifier miguel.c(12) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct st *' miguel.c(12) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *' miguel.c(12) : error C2223: left of '->poo' must point to struct/union miguel.c(12) : error C2059: syntax error : ')' miguel.c(13) : error C2059: syntax error : '{' miguel.c(13) : error C2059: syntax error : ')' miguel.c(14) : error C2143: syntax error : missing ')' before '(' miguel.c(14) : error C2143: syntax error : missing ')' before '&' miguel.c(14) : error C2091: function returns function miguel.c(14) : error C2143: syntax error : missing '{' before '&' miguel.c(14) : error C2059: syntax error : '&' miguel.c(14) : error C2059: syntax error : ')' miguel.c(14) : error C2059: syntax error : ')' miguel.c(15) : error C2059: syntax error : '}'