In c++
when I try to compile the following code I get a conflicting declaration error:
#include <iostream>
using namespace std;
typedef uint_least64_t uint;
int main() {
uint i = -1;
cout << i << endl;
}
error:
main.cpp:5:24: error: conflicting declaration ‘typedef uint_least64_t uint’
typedef uint_least64_t uint;
^~~~
In file included from /usr/include/stdlib.h:275:0,
from /usr/include/c++/6/cstdlib:75,
from /usr/include/c++/6/ext/string_conversions.h:41,
from /usr/include/c++/6/bits/basic_string.h:5417,
from /usr/include/c++/6/string:52,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from main.cpp:1:
/usr/include/x86_64-linux-gnu/sys/types.h:152:22: note: previous declaration as ‘typedef unsigned int uint’
typedef unsigned int uint;
^~~~
I assume that conflicting declaration error is because a type declaration for uint
already exists somewhere in the language, and I believe that the type is uint_least32_t
because:
#include <iostream>
using namespace std;
int main() {
uint i = -1;
cout << i << endl;
}
returns an integer value that is (2^32)-1. Therefore is it possible in c++
to redefine uint
as uint_least64_t
.