g++ --version
rand
, srand
and perhaps time(nullptr)
#include <iostream> #include <iomanip> using namespace std; int main() { srand(time(nullptr)); for(int i = 0; i < 10; ++i) { cout << rand() % 6 + 1 << endl; } return 0;
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2
-Wall
"This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros."
-Wextra
"This enables some extra warning flags that are not enabled by -Wall."
-Wpedantic
"Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specified by any -std option used."
-Wshadow
" Warn whenever a local variable or type declaration shadows another variable, parameter, type, class member (in C++) ..., or whenever a built-in function is shadowed. Note that in C++, the compiler warns if a local variable shadows an explicit typedef, but not if it shadows a struct/class/enum."
-Wconversion
"Warn for implicit conversions that may alter a value."
-std=
"Determine the language standard", this let's us use the c++23 standard
-g
Set the debugging level,
-O2
set the optimization level.
g++ -Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2 task1pre.cpp -o task1pre
Makefile
or makefile
, but not makefile.txt
or Makefile.txt
OBJS = task1
task1.cpp
holds your code.
CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2
all: ${OBJS}
make
at the command line.
clean: rm -rf ${OBJS} *.o
rm
, make is old and this marks the body of the target. These are the commands to apply to build that target.
OBJS = task1 CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wconversion -std=c++23 -g -O2 all: ${OBJS} clean: rm -rf ${OBJS} *.o