Difference between revisions of "C/C++"

From HCL
Jump to: navigation, search
(General)
Line 17: Line 17:
 
* [http://www.gnu.org/software/hello/manual/automake/Libtool-Convenience-Libraries.html Force C++ linking]
 
* [http://www.gnu.org/software/hello/manual/automake/Libtool-Convenience-Libraries.html Force C++ linking]
  
== General ==
+
== Tips & Tricks ==
 +
* [http://www.gnu.org/s/libc/manual/html_node/Date-and-Time.html#Date-and-Time Timing in C]
 
* Don't use non-standard functions, like [http://en.wikipedia.org/wiki/Itoa itoa]
 
* Don't use non-standard functions, like [http://en.wikipedia.org/wiki/Itoa itoa]
 
* [http://www.gnu.org/software/libc/manual/html_node/Program-Arguments.html Handling program arguments] (avoid <code>argp</code> since it is not supported on many platforms)
 
* [http://www.gnu.org/software/libc/manual/html_node/Program-Arguments.html Handling program arguments] (avoid <code>argp</code> since it is not supported on many platforms)

Revision as of 12:41, 18 March 2011

Coding

  • C++ programming style is preferrable. For example, in variable declarations, pointers and references should have their reference symbol next to the type rather than to the name. Variables should be initialized where they are declared, and should be declared where they are used. For more details, see Google C++ Style Guide
  • One-true-brace ident style
  • Coding header files
  • Learn from examples and use coding approaches from third-party software

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++

Tips & Tricks

  int size;
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  char names[size][MPI_MAX_PROCESSOR_NAME];
  • Implement delays in the execution of the program with help of nanosleep. Compared to sleep and usleep, nanosleep has the advantage of not affecting any signals, it is standardized by POSIX, it provides higher timing resolution, and it allows to continue a sleep that has been interrupted by a signal more easily.