// filename:c2011-6-8-6-1-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.8.6.1 The goto statement // compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.xx, 2013 // compile errors and/or wornings: // 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) { // Example 1 int need_to_reinitialize; goto first_time; for (;;) { // determine next operation /* ... */ if (need_to_reinitialize) { goto second_time; // reinitialize-only code /* ... */ first_time: // general initialization code /* ... */ continue; } // handle other operations /* ... */ } second_time:;// // Example 2 int n=2, j=3; goto lab3; // invalid: going INTO scope of VLA.//** // c2011-6-8-6-1-ex.c:34:1: error: goto into protected scope // goto lab3; // invalid: going INTO scope of VLA. // ^ //c2011-6-8-6-1-ex.c:45:1: note: label 'lab3' defined here // lab3: // ^ //c2011-6-8-6-1-ex.c:43:9: note: 'a' declared here // double a[n]; // ^ { double a[n]; a[j] = 4.4; lab3: a[j] = 3.3; goto lab4; // valid: going WITHIN scope of VLA. a[j] = 5.5; lab4: a[j] = 6.6; } goto lab4; // invalid: going INTO scope of VLA.//** // 1. LLVM3.2 error messages // c2011-6-8-6-1-ex.c:45:1: error: goto into protected scope // goto lab4; // invalid: going INTO scope of VLA. // ^ // 2.GCC4.9 error messages //c2011-6-8-6-1-ex.c:52:1: error: jump into scope of identifier with variably modified type // goto lab4; // invalid: going INTO scope of VLA.//** // ^ //c2011-6-8-6-1-ex.c:49:1: note: label 'lab4' defined here // lab4: // ^ //c2011-6-8-6-1-ex.c:43:9: note: 'a' declared here // double a[n]; // ^ return printf("6.8.6.1 The goto statement \n"); } // 1 LLVN(3.2) output may be // Segmentation fault: 11 // 2 GCC4.9 output //6.8.6.1 The goto statement