// c2011-6-5-15-ex.c // original examples and/or notes // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf // C2011 6.5.15 Conditional operator // compile and output mechanism // (c) kaizen@gifu-u.ac.jp, December.xx, 2013 // compile errors and/or warnings: // 1 (c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Target: x86_64-apple-darwin11.4.2 //Thread model: posix // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. // 2 gcc-4.9 (GCC) 4.9.0 20131229 (experimental) // Copyright (C) 2013 Free Software Foundation, Inc. #include int main(void) { const void *c_vp; void *vp; const int *c_ip; volatile int *v_ip; int *ip; const char *c_cp; //c_vp c_ip const void * printf("%d %d %d \n", c_vp, c_ip,c_vp ? c_vp : c_ip); //v_ip 0 volatile int * printf("%d %d %d \n",v_ip, 0,v_ip ? v_ip : 0); //c_ip v_ip const volatile int * printf("%d %d %d \n", c_ip,v_ip,c_ip ? c_ip : v_ip); //vp c_cp const void * printf("%d %d %d \n",vp, c_cp,vp ? vp : c_cp); //ip c_ip const int * printf("%d %d %d \n", ip, c_ip,ip ? ip : c_ip); //vp ip void * return printf("6.5.15 Conditional operator %d %d %d \n",vp,ip,vp?vp:ip); } // output may be //1357056720 0 1357056720 //0 0 0 //0 0 0 //0 0 0 //0 0 0 //6.5.15 Conditional operator 0 0 0 // GCC4.9 output // 1661771870 1388550864 1661771870 // 0 0 0 // 1388550864 0 1388550864 // 0 0 0 // 0 1388550864 1388550864 // 6.5.15 Conditional operator 0 0 0