-3

I've been using signed long longs and have had weird issues with it - i.e. inconsistent behavior. I.e.

long long i;
printf("%d", i);

This tends to print values which have no relevance to the actual value of i (this also occured with cout).

It also has random behavior with %, i.e.

if(i % x == 0)
        //some code

This would sometimes run i.e. if i = 15 and x = 5 it just wouldn't return true and therefore the if statement would not run the code.

It would tend to return true on x = 7 for some reason.

I believe that it may be a fault with the compiler which I believe was just the g++ compiler (it was at a competition).

Any ways to mitigate this or why it was doing this would be greatly appreciated.

Cjen1
  • 1,826
  • 3
  • 17
  • 47

1 Answers1

0

To print the various integer types using printf-style syntax requires horrible syntax - I suggest using the C++ type-safe iostreams instead.

Erik Alapää
  • 2,585
  • 1
  • 14
  • 25