3
#include <stdio.h>
int main()
{
    long long i,j;
    for(i = 1,j = 100;i<5000;i+= 50,j+=23)
    printf("%lld %lld\n",i,j);
    return 0;
}

The output for this code on IDEONE can be seen here : http://ideone.com/YCbc9V I am using GCC 4.8.1 on Windows XP, but instead of getting j + 23, I am getting all 0s on the second column of the output.

The code is same and so is the compiler, then hat is causing the change in output?

xanatos
  • 109,618
  • 12
  • 197
  • 280
reb94
  • 139
  • 1
  • 2
  • 8
  • 2
    Perhaps on your PC you have Visual Studio instead of GCC? With VC++ it's `%I64d`, not `%lld` – xanatos Aug 11 '13 at 15:38
  • OP is not using Visual Studio but GCC. However, this may be mingw GCC, in which case it uses MSVCRT.DLL with the buggy `printf` that does not understand `%lld`... – R.. GitHub STOP HELPING ICE Aug 11 '13 at 15:43
  • @xanatos No, I don't have VC++ on my PC. I only use Notepad++ and MinGW (GCC 4.8.1). And AFAIK, I64u works only for unsigned long long int. What would be the correct identifier for long long? – reb94 Aug 11 '13 at 15:45
  • @reb94 As written by R, try the `%I64d` :-) – xanatos Aug 11 '13 at 15:47
  • 1
    On Windows, it is safest to use `%I64` rather than `%ll`. Assuming it is MinGW, compile with `-D__USE_MINGW_ANSI_STDIO=1` on the command line or at the top of the file, before any includes, use `#define __USE_MINGW_ANSI_STDIO 1`. This will select the MinGW-provided functions like `__mingw_printf` that allow `%ll`. Also, compile with `-Wall`, and it will warn you about an extra format character when not using the MinGW functions. However, that shouldn't be your issue... –  Aug 11 '13 at 15:57
  • And why use long long at all here? You're only counting to 5000--that will fit into an int (even a short). – Lee Daniel Crocker Aug 11 '13 at 18:26
  • @LeeDanielCrocker : Maybe OP has not time to wait until `i<9223372036854775807` ;-) – moskito-x Aug 12 '13 at 03:00
  • @LeeDanielCrocker I had initially set the for loop till 50000000000 but after getting the wrong output I changed it to 5000 but forgot to change the variable type. – reb94 Aug 13 '13 at 14:39

0 Answers0