<p><strong>Avoid mixing C headers, functions, and casting if there is a corresponding C++ equivalent</strong></p><ol><li><strong>C Header/Function:</strong> use C++ equivalents. Use cmath not math.h, iostream not stdio.h <ul><li><code>Don't</code> Use C header/functions<ul><li><prestyle="border: 0;"><code>#include <math.h>
#include <stdio.h>
1.<strong>Avoid mixing C headers, functions, and casting</strong> use corresponding C++ equivalent. Example: use ```cmath``` not ```math.h```, ```iostream``` not ```stdio.h```
* _Don't_
``cpp
#include <stdio.h>
#include <math.h>
...
float powerOfTwo = powf( 2.f, 5.f );
printf ( "2^5 = %f\n", powerOfTwo );</code></pre></li></ul></li><li><code>Do</code> Use C++ header/functions<ul><li><prestyle="border: 0;"><code>#include < cmath >
<li><strong>Use C headers/functions when:</strong>
<ul><li>There is no C++ equivalent
<ul><li>C++ API is deprecated or not fully supported libraries ( <em>e.g.</em> MPI, CUDA_C, PETSc )</li><li>POSIX functionality <em>e.g.</em> unistd.h </li></ul></li><li>Language Interoperability is required
<ul><li>C++ –> C —> Fortran </li><li>C++ –> C —> JNI —> Java</li></ul></li></ul></li>
2.<strong>Exception for using C headers/functions:</strong>
* C++ API is deprecated or not fully supported libraries ( _e.g._ MPI, CUDA_C, PETSc )
* No POSIX equivalent in C++: _e.g._ ```unistd.h, shmem.h, sys/ipc.h```
* Language Interoperability through C
```
C++ --> C --> Fortran --> C --> C++
C++ --> C --> JNI --> Java --> JNI --> C --> C++
```
<li><strong>Type Casting:</strong> use C++11 style casting: static_cast, dynamic_cast, reinterpret_cast when corresponding instead of ( Type ) C style.<ul><li><code>Don't</code><ul><li><prestyle="border: 0;"><code> ( int ) foo;</code></pre></li></ul></li><li><code>Do</code>
<ul><li><prestyle="border: 0;"><code> static_cast< int > ( foo );</code></pre></li></ul></li>