Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

integer constant is too large for "long" type

Tags:

c

random

I am creating random integers with the following algorithm:

int random;

int i;
for (i = 0; i < RANDOM_COUNT; i++) {
    random = (((int) rand() << 0) & 0x0000FFFFd)
            | (((int) rand() << 16) & 0xFFFF0000d);
    fprintf(outputFile, " %d\n", random);
}

I am getting the following warning:

warning: integer constant is too large for "long" type

on this line:

| (((int) rand() << 16) & 0xFFFF0000d);

I am using GCC 3.4.3 to compile the code.

Does anyone know which part of the operation is triggering the warning?

like image 688
David Kaczynski Avatar asked Apr 19 '26 17:04

David Kaczynski


1 Answers

Does anyone know which part of the operation [(((int) rand() << 16) & 0xFFFF0000d);] is triggering the warning?

Yes, it's the 0xFFFF0000d, because it's 36 bits in size. Note that this number is equal to 0xFFFF0000D. You probably meant 0xFFFF0000.

Likewise, 0x0000FFFFd is equal to 0x0000FFFFD. You probably meant 0x0000FFFF.

like image 191
user1201210 Avatar answered Apr 22 '26 08:04

user1201210