c++ - Boolean_conversions Using reinterpret_cast<> -
can 1 give example
boolean_conversions using reinterpret_cast<> iam getting execution failure..any 1 explain ..
ex:
void boolean_conversions() { bool b = 0; int *i = reinterpret_cast<int*> (&b); // iam expecting *i 0/false ,but showing runtime error } edit: in iso standard section $5.2.10, para 1:
"the result of expression reinterpret_cast<t>(v) result of converting expression v type t. if t reference type, result lvalue; otherwise, re sult rvalue , l-value r-value (4.1), array pointer (4.2), , function pointer (4.3) standard c onversions performed on the expression v. types sh not defined in reinterpret_cast." from iam trying ..i did many conversions ..like array_to_pointer,function_to_pointer,integral/pointer_conversions ,etc...but don't know why failing boolean conversions.
can 1 tell why failing ..otherwise tell boolean conversions using reinterpret_cast.
mostly giving run time failure in g++.cc/edg/codepad..etc compilers
please explain
no, output not defined. note conversion undefined.
on machine *i = 0xcccccc00
note lsb 00
which corresponds value of bool variable initialized 0(false). byte pattern in other 3 bytes (assuming size of int 32-bits) unspecified , depends on there in memory/endianness etc.
technically, undefined behavior because deferencing memory location (all of) did not reserve/allocate.
Comments
Post a Comment