//.............................................................................. // // This file is part of the Jancy toolkit. // // Jancy is distributed under the MIT license. // For details see accompanying license.txt file, // the public copy of which is also available at: // http://tibbo.com/downloads/archive/jancy/license.txt // //.............................................................................. // Safe data pointers and safe pointer arithmetic were among the biggest // motivators in creating Jancy. // By default, Jancy data pointers are 'fat': in addition to the actual pointer // they also carry the pointer validator, which contains the permitted address // range, pointer type, and the scope level. // This sample code demonstrates range checks performed by the Jancy runtime on // pointer access. //.............................................................................. // entry point int main () { printf ("main ()\n"); int a [] = { 10, 20, 30 }; int* p = a; int* end = p + countof (a); for (; p < end; p++) printf ("*p = %d\n", *p); // now 'p' points beyond the end of array, accessing it will trigger // the "data pointer out-of-range" runtime error // int x = *p; // <-- runtime error // using index operator involves range-checked as well size_t i; for (i = 0; i < countof (a); i++) printf ("a [%d] = %d\n", i, a [i]); // now 'i' holds the index that is outside the array boundary, accessing it // will trigger the "data pointer our of range" runtime error // a [i] = i; // <-- runtime error return 0; } //..............................................................................