Posted to tcl by apw at Fri Aug 03 19:48:25 GMT 2007view raw

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

Comments

Posted by patthoyts at Fri Aug 03 20:00:12 GMT 2007 [text] [code]

C:\temp\func>cl -W3 -Od -Zi -MDd aps.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. aps.c aps.c(13) : warning C4047: 'return' : 'int ' differs in levels of indirection fr om 'void *' aps.c(18) : error C2059: syntax error : '{' aps.c(18) : error C2065: 'v' : undeclared identifier aps.c(18) : warning C4047: '==' : 'int ' differs in levels of indirection from ' void *' aps.c(18) : error C2223: left of '->poo' must point to struct/union aps.c(18) : error C2059: syntax error : ')' aps.c(19) : error C2143: syntax error : missing ')' before '(' aps.c(19) : error C2143: syntax error : missing ')' before '&' aps.c(19) : error C2091: function returns function aps.c(19) : error C2143: syntax error : missing '{' before '&' aps.c(19) : error C2059: syntax error : '&' aps.c(19) : error C2059: syntax error : ')' aps.c(19) : error C2059: syntax error : ')' aps.c(20) : error C2059: syntax error : 'return' aps.c(21) : error C2059: syntax error : '}'

Posted by patthoyts at Fri Aug 03 20:04:41 GMT 2007 [text] [code]

int main(int argc, char *argv[]) { int j = ({struct st *v; v = moo(1); v == ((void *)0) ? ((void *)0) : v->poo;}); fprintf((&_iob[2]), "j:%d\n", j); return 0; }

Posted by kbk at Fri Aug 03 20:11:14 GMT 2007 [text] [code]

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