The following code gives invalid result with optimization (Release configuration).#include <stdio.h>#include <stdlib.h>typedef char T; // char or short#define N 4 // any from 4 to 10voidint2Buf (T * buf, int value, int nBits){ int i; for (i = 0 ; i < nBits; i++) { buf[i] = value & 1; value >>= 1; }}voidprintBuf (T * buf, int nBits){ int i; printf ("bits: "); for (i = 0; i < nBits; i++) { printf ("%d", (int)buf[i]); } printf ("\n");}intmain (void){ T buf[32]; int2Buf (buf, 0x55555555, N); printBuf (buf, N); int2Buf (buf, abs(0x55555555), N); printBuf (buf, N); return 0;}
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...