GCC hidden/little-known features -


this attempt start collection of gcc special features not encounter. comes after @jlebedev in question mentioned "effective c++" option g++,

-weffc++ option warns c++ code breaks of programming guidelines given in books "effective c++" , "more effective c++" scott meyers. example, warning given if class uses dynamically allocated memory not define copy constructor , assignment operator. note standard library header files not follow these guidelines, may wish use option occasional test possible problems in own code rather compiling time.

what other cool features there?

from time time go through current gcc/g++ command line parameter documentation , update compiler script more paranoid kind of coding error. here is if interested.

unfortunately didn't document them forgot most, -pedantic, -wall, -wextra, -weffc++, -wshadow, -wnon-virtual-dtor, -wold-style-cast, -woverloaded-virtual, , few others useful, warning me of potentially dangerous situations. aspect of customizability, forces me write clean, correct code. served me well.

however not without headaches, -weffc++. few examples:

  • it requires me provide custom copy constructor , assignment operator if there pointer members in class, useless since use garbage collection. need declare empty private versions of them.
  • my noninstantiable class (which prevents instantiation of subclass) had implement dummy private friend class g++ didn't whine "only private constructors , no friends"
  • my final<t> class (which prevents subclassing of t if t derived virtually) had wrap t in private wrapper class declare friend, since standard flat out forbids befriending template parameter.
  • g++ recognizes functions never return return value, , throw exception instead, , whines them not being declared noreturn attribute. hiding behind true instructions didn't work, g++ clever , recognized them. took me while come declaring variable volatile , comparing against value able throw exception unmolested.
  • floating point comparison warnings. oh god. have work around them writing x <= y , x >= y instead of x == y acceptable.
  • shadowing virtuals. okay, useful prevent stupid shadowing/overloading problems in subclasses still annoying.
  • no previous declaration functions. kinda lost importance started copypasting function declaration right above it.

it might sound bit masochist, whole, these cool features increased understanding of c++ , general programming.

what other cool features g++ has? well, it's free, open, it's 1 of used , modern compilers, consistently outperforms competitors, can eat people throw @ it, available on virtually every platform, customizable hell, continuously improved, has wide community - what's not like?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -