Laxkit  0.0.7.1
Coding Say What?

This page is for various programming tricks and various things about coding to remember. It especially helps non-professional programmers (like me) from tripping over the same mistakes. One may find lots of C++ info at, for instance http://www.cppreference.com/operator_precedence.html and also http://www.cplusplus.com . Also, the info pages for gcc and libc are invaluable, as are all the Xlib and related documents in the Debian xspecs package.


C++ operator precedence roughly goes something like this:
(good chart at http://www.cppreference.com/operator_precedence.html)

[]   ()   ->   .   ::   (thing)++   (thing)--
!   ~   ++(thing)   --(thing)   -(unary)   +(unary)
  *(dereference)   &(address of)   (cast)   sizeof
->*  .*    
*    /    %   
+   -
<<   >>   
<   <=   >    >=   
==   !=
&    ^    |   &&   ||   e1?e2:e3
=   +=   -=   *=   /=   %=   &=   |=   ^=   <<=   >>=
,

! through (sizeof) go right to left, as do all the thing= operators. The rest all go left to right.

& through ?: are evaluated left to right on their own. The ops on each other line are evaluated as they occur, so a+b-c+d would evaluate in order a b c d since + and - have same level, so to speak.


Some useful Vi key mappings which you can put in your ~/.vimrc file:

 set mouse=a
 set tabstop=4
 set sw=4
 
  " Make '  //blah' into '  blah'
 map <F3> :s/^\(\s*\)\/\//\1/<CR>
 
  " Make '  blah' into '  //blah'
 map <F4> :s/^\(\s*\)/\1\/\//<CR>

  " Make '//  blah' into '  blah'
 map <F11> :s/^\/\///<CR>

  " Make '  blah' into '//  blah'
 map <F12> :s/^/\/\//<CR>

Don't forget to have a virtual destructor in your functions that get derived from!!!


to make shared library, objects must be compiled without -g something like:

g++ -fPIC -c blah.cc -o blah.o

and linked thus:

g++ -shared -fPIC -o blah.so blah.o ...

Template compilation question:

Currently, my templates have a *.h and *.cc, and I wonder if it is a big disadvantage when including the lists.cc (or refcounter.cc) in a window class.. does that imply that every object file that has that included is creating its own local functions for all the templates from all the include files, rather than just the relevant ones for that file?? did a very simplified basic check with lists.cc/h and each object file is compiling its own functions, but it is not clear whether all of those are linked in, or just the most recent, or what??

Answer?

The info pages for gcc say that g++ in conjunction with gnu ld version 2.8 or later collapses all the template code to single instances of the code. For my current system, ld is at version 2.16, so if I've understood what I read there, it should be ok to include the template.h and template.cc in each file that the template is used. It will be compiled for each file, but collapsed when linked all together.


Mon Feb 17 2014 11:52:58, Laxkit