Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Help with printing a bit pattern with printf and %x
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Eric Sosman, post: 5088243"] Aside: This won't always do what you want. The compiler has a lot of freedom in laying out bit-fields, and different compilers will do it differently. The short (and uninformative) answer is: When the argument and the conversion specification disagree, the behavior is undefined. Most likely, the "%x" specifier looks at half of the `double' argument,[*] finds a whole lot of zero bits, interprets them as the `unsigned int' it was expecting, and prints their value. Even that much isn't guaranteed, though. Some machines pass floating-point arguments in a different way than others (perhaps in dedicated F-P registers), so the "%x" would look for its argument in one place while the `1.0' inhabits another. GIGO. [*] Yes, the type of `1.0' is `double', not `float'. Even if you were to write `1.0f' it wouldn't help: the "default argument promotions" would convert the `1.0f' to `double' while marshalling the arguments for printf. There is no way to pass a `float' -- or `short', or `char' -- argument to printf. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Help with printing a bit pattern with printf and %x
Top