// 1 filename:c2011-3-14-ex. // ver 0.1 December.29, 2013 // ver 0.2 January 11, 2014 add 2 sets of input for clarify about warning and assignment. // 2 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 3.14 memory location // 3 compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013 // 4 compile errors and/or wornings: // 4.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 // Xcode 5.0.2/LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Command/Options: cc -std=c11 -Wall misra-C-2-1-ex-ui-wicm4a.c // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. // 4.2. gcc-4.9 (GCC) 4.9.0 20131229 (experimental) C90/C99/C2011, 32/64 bit, http://gcc.gnu.org/onlinedocs/gcc/Standards.html // Copyright (C) 2013 Free Software Foundation, Inc. http://gcc.gnu.org/gcc-4.9/changes.html // Command/Options: gcc std=c11 -Wall misra-C-2-1-ex-ui-wicm4a.c // Configuration:brew install gcc49 #include //either an object of scalar type, or a maximal sequence of adjacent bit-fields all having //nonzero width struct { char a; int b:5, c:11, :0, d:8; struct { int ee:8; } e; }f; int main(void){ f.a = 1; f.b=2; f.c=3; f.d=4; f.e.ee=5; printf(" %d %d %d %d %d\n", f.a,f.b,f.c,f.d,f.e.ee); f.a = 1000001; f.b = 2000002; f.c = 3000003; f.d = 4000004; f.e.ee= 5000005; printf(" %d %d %d %d %d\n", f.a,f.b,f.c,f.d,f.e.ee); f.a = 1000000000001; f.b = 2000000000002; f.c = 3000000000003; f.d = 4000000000004; f.e.ee= 5000000000005; printf("3.14 memory location %d %d %d %d %d\n", f.a,f.b,f.c,f.d,f.e.ee); } // no error, no warning // output may be // 3.14 memory location 1 2 3 4 5 // after add two sets of inputs. 10 warnings and output are // 1 2 3 4 5 // 65 2 -317 4 69 //3.14 memory location 1 2 3 4 5