Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC 5, 6 and 7 on OSX do not support uint

Tags:

c++

macos

gcc

I installed GCC 5, 6 and 7 on OSX 10.12 with Homebrew. Compiling the simple code

#include <iostream>

int main() {
    uint foo = 10;
    std::cout << foo << std::endl;
}

returns an error:

$ g++-7 -o uint uint.cpp
uint.cpp: In function 'int main()':
uint.cpp:5:5: error: 'uint' was not declared in this scope
     uint foo = 10;
     ^~~~
uint.cpp:5:5: note: suggested alternative: 'int'
     uint foo = 10;
     ^~~~
     int
uint.cpp:6:18: error: 'foo' was not declared in this scope
     std::cout << foo << std::endl;
                  ^~~
uint.cpp:6:18: note: suggested alternative: 'feof'
     std::cout << foo << std::endl;
                  ^~~
                  feof

This error does not happen with other compilers I have access to. The code works fine with clang++ (on OSX) and with gcc4/5/6 on Linux systems. Is there a configuration switch missing on my side? Or could this be because gcc links with libstdc++ and not with libc++ which is standard on OSX?

like image 215
Pascal Avatar asked Sep 05 '25 03:09

Pascal


1 Answers

This is supposedly a problem with GLIBC. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59945 and Jonathan Wakely's answer.

Glibc defines it:

#ifdef __USE_MISC
/* Old compatibility names for C types.  */
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
#endif

__USE_MISC is defined because G++ defines _GNU_SOURCE, which is well known to cause problems, e.g. PR 11196 and PR 51749

This particular namespace pollution only occurs with C++11 because only needs to #include in C++11 mode to define std::to_string, std::stoi etc. but in general the problem affects C++98 too.

like image 174
Brian Sidebotham Avatar answered Sep 07 '25 17:09

Brian Sidebotham