Posted to tcl by miguel at Fri Aug 03 20:08:04 GMT 2007view pretty
#include <stdio.h> typedef struct st {int poo;} st; #define foo(x) ({st *v; v = moo(x); v == NULL ? 0 : v->poo; }) st * moo(st *x) { return x; } int main(int argc, char *argv[]) { st x = {3}, *y = NULL; int j = foo(&x); int k = foo(y); fprintf(stderr, "j:%d, k:%d\n", j, k); }
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 : '}'