Home Dashboard Directory Help
Search

Possible minor bug in Visual C++ 2010/2012 regarding conditional operator by Xavier Roche


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 754807
Opened: 7/20/2012 7:53:22 AM
Access Restriction: Public
0
Workaround(s)
view
3
User(s) can reproduce this bug

Description

The following example:

const static volatile double zero = 0.0;

#define EXP(E) printf("%s == %u\n", #E, E)

int main(int argc, char **argv) {
EXP(zero ? 1 : 0);
EXP(-zero ? 1 : 0);
EXP(0.0 ? 1 : 0);
EXP(-0.0 ? 1 : 0);

return EXIT_SUCCESS;
}

Should print the following result:

zero ? 1 : 0 == 0
-zero ? 1 : 0 == 0
0.0 ? 1 : 0 == 0
-0.0 ? 1 : 0 == 0

However, the last two lines shows "1" using Visual C++ 2010 (cl.exe 16.00.30319.01 for x64 or x86)

The same behavior is seen in the latest release, too, according to David Lowndes (*)

It was said (comp.lang.c) that according to the C standard, it should be 0 (3.3.15, "Conditional operator")

(*) See http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/8caf1a5a-d421-4a92-b924-468327afaec3
Details
Sign in to post a comment.
Posted by Microsoft on 9/6/2012 at 3:59 PM
Hi Xavier:
    A fix for this issue has been checked into the compiler sources. The fix should show up in the next major release of Visual C++.
    To workaround the issue in VS2012 or earlier version, you can change the condition to explicit comparision. For example,

    (zero != 0.0) ? 1 : 0

Xiang Fan
Visual C++ Team
Posted by Microsoft on 7/22/2012 at 11:06 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 7/20/2012 at 8:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.