Subj : Re: Any help on why? To : borland.public.cpp.borlandcpp From : maeder Date : Wed Jul 07 2004 10:39 pm Bob Gonder writes: > Thomas Maeder [TeamB] wrote: > >>X and lX are for integral values. Using them for something else is an even >>uglier hack than using the *printf() machinery at all. > > And you call the below code *Not* ugly? The ugliness derives from the problem. In contrary to your code, mine is at least correct. >>To peek at the internals of, say, a double, the portable way is to >>treat it as an array of unsigned char, as in >> >>double d(3.11415); >>unsigned char const *const begin(reinterpret_cast(&d)); >>unsigned char const *const end(begin + sizeof d); >>for (unsigned char const *c = begin; c!=end; ++c) >> printf("%u ",static_cast(*c)); > > Yeah, but you want to use hex. You can't see the bits in 123. Ok, change %u to %hu. > My BC++ doesn't support 'reinterpret_cast' That's some new-age mumbo > jumbo designed to slow down programmers. Actually, it was designed to help programmers. The single most important source of programming errors is incorrect type casts. So let's better - invent ugly keywords that make us think once more before casting - make them stand out so that they are easily spotted > I suppose it's so hard to > type that it encourages programmers to do *anything* (even use the > correct types!) to avoid it. Spot on. You only do it if you absolutely must. > Not to mention, the OP's code was C not C++ to begin with. Irrelevant. .