Muniyasamy V
Muniyasamy V

Reputation: 81

Warning this decimal constant is unsigned only in ISO C90

#include<stdio.h>

int main(void) {

    int t;
    long long n = 4294967295;
    //printf("%lu",n);
    return 0;
}

Whenever I run the above code, the compiler shows the following warning

[Warning] this decimal constant is unsigned only in ISO C90

What's wrong in my code?

Upvotes: 2

Views: 4114

Answers (2)

M.M
M.M

Reputation: 141618

In ISO C the behaviour of 4294967295 changed between C90 and C99.

In C90, on normal systems this is an unsigned value, unsigned int (on 32-bit system) or unsigned long (on 16-bit system). However in C99 this is a signed long long on those systems.

You could disable this warning, or use an integer suffix to show that you understand the issue, e.g. 4294967295LL.

Upvotes: 2

tdao
tdao

Reputation: 17668

For long long int, you need %lld format specifier:

long long n = 4294967295;
printf("%lld", n);

Using wrong format specifier %lu for long long int type causes undefined behaviour.

Upvotes: 0

Related Questions