ForestClaw / forestclaw

Quadtree/octree adaptive PDE solver based based on p4est.
http://www.forestclaw.org
BSD 2-Clause "Simplified" License
57 stars 21 forks source link

Avoid potential double extern C #290

Closed tim-griesbach closed 8 months ago

tim-griesbach commented 8 months ago

The includes in overlap.h are currently after the extern "C". This can cause problems if at least one of these includes also sets extern "C". For example, I observed this with the follwowing compile error since mpi.h contains an extern "C" in the MPI implementation that I used.

In file included from /usr/include/mpich/mpi.h:2239,
                  from ../forestclaw/sc/src/sc.h:103,
                  from ../forestclaw/sc/src/sc_containers.h:39,
                  from ../forestclaw/p4est/src/p4est_base.h:48,
                  from ../forestclaw/src/fclaw_base.h:55,
                  from ../forestclaw/src/fclaw_options.h:35,
                  from ../forestclaw/src/fclaw2d_options.h:35,
                  from 
../forestclaw/applications/clawpack/advection/2d/filament_swirl/overlap.h:35,
                  from 
../forestclaw/applications/clawpack/advection/2d/filament_swirl/overlap.c:27:
/usr/include/mpich/mpicxx.h:2725:13: error: conflicting declaration of C 
function ‘void MPI::Init(int&, char**&)’
  2725 | extern void Init(int &, char **& );
       |             ^~~~
/usr/include/mpich/mpicxx.h:2724:13: note: previous declaration ‘void 
MPI::Init()’
  2724 | extern void Init(void);
       |             ^~~~
/usr/include/mpich/mpicxx.h:2727:12: error: conflicting declaration of C 
function ‘int MPI::Init_thread(int&, char**&, int)’
  2727 | extern int Init_thread(int &, char **&, int );
       |            ^~~~~~~~~~~
/usr/include/mpich/mpicxx.h:2726:12: note: previous declaration ‘int 
MPI::Init_thread(int)’
  2726 | extern int Init_thread(int);
       |            ^~~~~~~~~~~

Therefore, I moved the includes before the extern "C". This also resolves the compilation error reported above.