Long long

I’m trying to use long long type (env: cygwin)

#include <stdio.h>
#pragma include_noerr <long.dll> // compiled
int main() {
  long long l = 1000 * 1000 * 1000;
  printf("%lld", l);
  return 0;
}

the result:

good.

more:

  long long l = 1000 * 1000 * 1000 * 100;

[ul]
$ cint testlong.c
1215752192
[/ul]

Hm…

It would appear long long is not working as real 64-bit integer.

Yes, it’s something wrong with long long type, not printf

#include <stdio.h>
#pragma include_noerr <long.dll>

int main() {
  long long l = 1000 * 1000 * 1000 * 100;
  long long l2 = l / 1000;
  printf("l: %lld, l2: %lld\n", l, l2);
  return 0;
}

[ul]
$ cint testlong.c
l: 1215752192, l2: 1215752
[/ul]

Damn it works :slight_smile:

#include <stdio.h>
#pragma include_noerr <long.dll>

int main() {
  long long l = (long long)1000 * (long long)1000 * (long long)1000 * (long long)100;
  long long l2 = l / (long long)1000;
  printf("l: %lld, l2: %lld\n", l, l2);
  return 0;
}

$ cint testlong.c
l: 100000000000, l2: 100000000

yet it fails in this way:

#include <stdio.h>
#pragma include_noerr <long.dll>

int main() {
  long long l = 100000000000L;
  long long l2 = l / (long long)1000;
  printf("l: %lld, l2: %lld\n", l, l2);
  return 0;
}

$ cint testlong.c
Error: integer literal too large FILE:testlong.c LINE:5
!!! return from main() function

cint> q
Bye… (try ‘qqq’ if still running)

Hello,

You already found this. It is pretty good.
With your first example, right value is an operation of integers that have
32bit information. So, all of the operators are 32bit version. Then all the sudden, assignment is done for 64bit integer. But, information is truncated to 32bit already by the operators.

In order to workaround the problem, you need to specify, at least, one item of right value formula is long long. For example,

long long l = 1000LL * 1000 * 1000 * 100;

Thank you
Masa Goto