On 10/04/2005 09:32 PM, William A. Rowe, Jr. wrote: > Brian Candler wrote: >
[..cut..] > >> P.S. The reverse case is sillier, given that the value is moving to a >> *larger* type and therefore no data loss can occur: >> >> short a; >> long b = a; // (7) no warning >> >> short a; >> void *b = a; // (8) warns "pointer from integer without a >> cast" (ok) >> void *c = (void *)a; // (9) warns "cast to pointer from integer of >> different size" >> void *d = (void *)(long)a; // (10) even more stupid!!! >> >> Note that having a 'large enough' integral type in case (10) is not good >> enough. We need to cast 'a' to an integral type which is *exactly* the >> same >> size as a void *, to silence this particular warning. > > > I agree with your assertion that the code example above IS a gcc bug. > This is expected in C++, but the waning (9) above is completely bogus, I do not think so. While "a" does fit in "c" from the storage point of view converting "c" to a different pointer type e.g. (char *) and dereferencing it afterwards most likely leads to SIGBUS or SIGSEGV. So I think a warning is justified here. > as you illustrate with line (7) above. > This is different as no harm can be expected here like in (9). [..cut..] Regards Rüdiger
