Salut, Water, On Thu, 6 Mar 2008 20:51:08 +0800, Water NB wrote: > it run as below: > 0xfffffffffdcf7a70 ^^^^^^^^^^^^^^^^^^ 64-bit addr created from 32-bit addr, upper 32 bit set to 1 (since the bit 31 of the address was set (4th nibble is 0xfd)) > if I use #if 0, > it run correctly. > 0x7f7ffdcf7a70 ^^^^^^^^^^^^^^ Genuine 64-bit address, not truncated and extended > why inet_ntoa return a bad address? > on NetBSD i386, it always return a valid address. why not here? > Since it can return a bad address, how can I know if it is a bad or > good? > Or is it a bug? The problem you're facing is that if you use the wrong header, inet_ntoa is not defined. C symbols are stored without any reference to their types, so the compiler assumes they return int by default. Now int is a 32-bit data type on amd64 and friends, so you're loading an implicitly signed 32-bit constant into a 64-bit register. In order to preserve the sign (0xfd indicates that the 31st bit is set, making the number negative), your processor sets the upper 32 bit to 1, making the number theoretically negative. So you cut off 32 precious bits of your address and set them to 1 implicitly, which gives you the invalid pointer. Just include the correct header which defines the function, and use CFLAGS=-W -Wall next time you compile something, which warns you of mistakes like this one. Regards, Tonnerre
Attachment:
signature.asc
Description: PGP signature