I am studying Bjarne Stroustrup's book 'Programming Principles and Practice Using C++'. I downloaded his header file from here and used the following compiling command in VSCode on Windows:
g++ -Wall -Wextra -Wconversion -pedantic -std=c++17 -g -c main.c
The compiler threw up a bunch of errors:
std_lib_facilities.h: In member function 'char& String::operator[](unsigned int)':
std_lib_facilities.h:114:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
if (i<0||size()<=i) throw Range_error(i);
~^~
std_lib_facilities.h: In member function 'const char& String::operator[](unsigned int) const':
std_lib_facilities.h:120:8: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
if (i<0||size()<=i) throw Range_error(i);
~^~
std_lib_facilities.h: At global scope:
std_lib_facilities.h:222:2: warning: extra ';' [-Wpedantic]
};
My questions are:
- Is it correct to remove the semi-colon on line 222? The code in question:
default_random_engine& get_rand()
{
static default_random_engine ran;
return ran;
};
- What is the possible fix for the
unsigned expression < 0 is always false
? - What should I watch out for in the future going forward using g++ (mingw64)? If possible, what are some resources to learn how to use about the g++ compiler effectively?
The code to be compiled was just a simple hello world. Thanks