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
Union, ternary operator, Macro, printf don't cooperate for me. Help?
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="Christian Bau, post: 1682621"] What is the type of ((Stochastic) ? var.i : var.f) ? The type of var.i is int. The type of var.f is double. Whatever value is picked depending on the value of Stochastic, will then be converted according to the "usual arithmetic conversion"s to type double, and that is the type of result. %lu is the wrong format to print a double value. You get undefined behavior, which causes the rather interesting output. Use a double format instead. Here you convert the double value to unsigned long, so you use %lu to print an unsigned long value. Everything is fine here. If var.f had a fractional part and Stochastic is zero then the fractional part would be lost. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Union, ternary operator, Macro, printf don't cooperate for me. Help?
Top