SCOREC / pumi-pic

support libraries for unstructured mesh particle in cell simulations on GPUs and CPUs
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Question about pragma vs. include guards #54

Closed MatthewChristoff closed 3 years ago

MatthewChristoff commented 3 years ago

As I was going through the code for CSR and particle_structure, I noticed that we use #pragma instead of standard include guards in most of these files. I'm not super familiar with #pragma, so I looked it up and it seems that it's not portable to some older compilers and it has some issues with symbolic links to the same file. Does this matter to us?

Here's a link to the Wikipedia page which provides some general information (including some portability version references), and here's a Microsoft Docs page that discusses some specifics about when to use/not to use #pragma.

diamog commented 3 years ago

I have heard of the issues with #pragma once before, but I have never seen them in practice. Certainly, if there is a compiler we need to target that does not support it then we should switch to the #ifdef guards.

The reason I prefer #pragma once is because on multiple occasions I have experienced developers copy and paste files without changing the previous unique string used for the #ifdef. This results in nonsensical compiler errors that are nontrivial to find if unaware of the situation. So, I find the #pragma once option to be less error-prone.

MatthewChristoff commented 3 years ago

Thanks for the info.