Hi all
I am using Kubuntu 16.04
I write code in c++ and compile it using g++ .I think the version of c++ is c++ 11.
whatever be the reason i cannot use auto,unordered map and some other things in my pc.
I have googled quite a bit about updating to c++ 14 or some more advanced version which supports above things atleast.But in vain,I couldn't find any thing helpful that solves my problem.
Can someone help me how to run program in c++14 in my system??
And also I see some experienced coders compile program using something different rather than just
g++ prog.cpp Can someone elaborate on this ???
BTW Happy New Year to all of you
The required switch is
-std=c++14
. Without explicitly selecting the Standard, it will default to C++11 for GCC 6.x and C++03 for GCC 5.x and below (g++ -v
could be used to check the compiler version). However, you definitely should enable compiler warnings to work with GCC.I use this script for C++ coding. Actually, it doesn't have an option to compile with C++14, though you can change the defaults in
src/ec.py:315
.can u say what is that you get by running with above mentioned script better than normal g++ prog.cpp
ec a
instead ofg++ -std=c++14 -Wall -Wextra -pedantic -Wformat=2 -Wfloat-equal -Wlogical-op -Wredundant-decls -Wconversion -Wcast-qual -Wcast-align -Wuseless-cast -Wno-shadow -Wno-unused-result -Wno-unused-parameter -Wno-unused-local-typedefs -Wno-long-long -DLOCAL_PROJECT -g -DLOCAL_DEBUG -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC a.cpp -o a && ./a <a.in
. And you can switch to release build by just adding-r
.<bits/stdc++.h>
? Compilation time, again. Up to 3 times faster.Q: Why Makefile?
A: 5 lines vs. 500+ lines with much more features
Q: Why precompiled headers?
A: I just think that it's better then hard-coding all the function/class names in smth like this.
use alias for the command for the corresponding shell
for eg I use "g main.cpp" and it will compile main.cpp into program named "a"
then I can just execute a "./a"
alias g='g++ additional_parameters -o a'
You're right, ec once was a little Bash alias, and it has grown into five hundred-lines Python script for these years.
Simply put, use
g++ prog.cpp -std=c++14
instead of justg++ prog.cpp
Recently I spent lot of unnecessary time(worth in total of more than 7 hours in past 4 days) in some debugging related to some issues like uninitialized variables, accessing out of bounds of an array. And everything works fine on my system but gives error when submitted.
I believe that there will be flags which will be useful for avoiding such things. Can somebody give a brief on the flags they generally use when compiling.
PS: Please give a one liner of what each flag is responsible (if possible).
Sanitizer flags are useful for this kind of bugs:
-fsanitize=address,undefined
finds most common cases of undefined behaviour and invalid memory access. You can read more here.This is a great starting point. Try these and remove those which feel obnoxious.