Difference between revisions of "C/C++"

From HCL
Jump to: navigation, search
(Creating libraries with Autotools)
(Creating libraries with Autotools)
Line 20: Line 20:
  
 
== Creating libraries with [[Autotools]] ==
 
== Creating libraries with [[Autotools]] ==
* Prepare two sets of headers:
+
* includes (for the include directory): <code>include_HEADERS = ...</code>
** includes (for the include directory): <code>include_HEADERS = ...</code>
+
* library: static <code>lib_LIBRARIES = library.a</code> or dynamic <code>lib_LTLIBRARIES = library.la</code>
** define static <code>lib_LIBRARIES = library.a</code> or dynamic <code>lib_LTLIBRARIES = library.la</code>
+
* sources (internal C data structures and C++ template classes): <code>library_X_SOURCES = library.h ...</code>, where <code>X</code> = <code>a</code> or <code>la</code>
** sources (internal C data structures and C++ template classes): <code>library_X_SOURCES = library.h ...</code>, where <code>X</code> = <code>a</code> or <code>la</code>
+
** <code>library.h</code> is a [http://en.wikipedia.org/wiki/Precompiled_header precompiled header] (contains common headers and symbols), which is to be included in most of source files of the library
*** <code>library.h</code> is a [http://en.wikipedia.org/wiki/Precompiled_header precompiled header] (contains common headers and symbols), which is to be included in most of source files of the library
+
 
 +
For example, see:
 +
* http://hcl.ucd.ie/repos/CPM/trunk/MPIBlib/benchmarks/Makefile.am
 +
* http://hcl.ucd.ie/repos/CPM/trunk/MPIBlib/collectives/Makefile.am

Revision as of 16:05, 16 February 2010

Coding

Commenting

  • Place Doxygen comments in header files (before declarations of namespaces/classes/structs/typedefs/macros) and main source files (for documenting tools and tests)
  • Use double forward slash for short comments in the code

C++

  • Mixing C/C++
  • Template C++ is preferrable from the point of view of runtime performance
  • Use plain C unless you need flexible data structures or STL/Boost functionality
  • Provide main API in C

General

Creating libraries with Autotools

  • includes (for the include directory): include_HEADERS = ...
  • library: static lib_LIBRARIES = library.a or dynamic lib_LTLIBRARIES = library.la
  • sources (internal C data structures and C++ template classes): library_X_SOURCES = library.h ..., where X = a or la
    • library.h is a precompiled header (contains common headers and symbols), which is to be included in most of source files of the library

For example, see: