1
0
mirror of https://codeberg.org/emilwilliams/chad_standard synced 2024-11-22 03:54:18 -05:00

Define At Beginning Header Guard

This commit is contained in:
Chad C. Starz 2024-07-20 17:17:05 +00:00
parent 6092c8d06c
commit 637c4d5d30
No known key found for this signature in database
GPG Key ID: CEEBC9208C287297
8 changed files with 78 additions and 3 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
auto
chad.pdf
chad.log
chad.aux
*.out
*.o

View File

@ -82,16 +82,18 @@ type a = {
Do not use relative pathing in headers, instead use compiler flags Do not use relative pathing in headers, instead use compiler flags
or full paths to enable your compilation. or full paths to enable your compilation.
\bitem{Define At End Header Guard} \\ \bitem{Define At Beginning Header Guard} \\
Use this kind of header guard: Use this kind of header guard:
\begin{verbatim} \begin{verbatim}
#if HEADER_H #if HEADER_H
...
#define HEADER_H #define HEADER_H
#endif ...
#endif // HEADER_H
\end{verbatim} \end{verbatim}
\bitem{No Double Blank Line} Shortens code and removes blank redundancy, use Single Blank Lines as much you want.
\bitem{Namespacing For Externally Exposed Headers \& Variables} \bitem{Namespacing For Externally Exposed Headers \& Variables}
Add a namespace suffix for headers \& variables meant to be used Add a namespace suffix for headers \& variables meant to be used
outside your project. outside your project.

View File

@ -0,0 +1,8 @@
## Justification for Define At End Header Guard -> Define At Beginning Header Guard.
Define At End Header Guard is a very pretty style for Header Guards, however is nonviable due to:
Define At End Header Guard fail to properly handle circular dependence as the define comes after the dependency,
hence using Define At Beginning Header Guard is always preferable.
This was brought to light by an long-term Anonymous contributor, and is responsible for this change and justification.

View File

@ -0,0 +1,10 @@
#ifndef A_H
#include "b.h"
struct a {
int i;
};
#define A_H
#endif

View File

@ -0,0 +1,10 @@
#ifndef A_H
#define A_H
#include "bc.h"
struct a {
int i;
};
#endif

View File

@ -0,0 +1,10 @@
#ifndef B_H
#include "a.h"
struct b {
int i;
};
#define B_H
#endif

View File

@ -0,0 +1,10 @@
#ifndef B_H
#define B_H
#include "ac.h"
struct b {
int i;
};
#endif

View File

@ -0,0 +1,19 @@
// @BAKE gcc $@ -o $*.out $+
#ifndef CIRCULAR
# define CIRCULAR 0
#endif
#if CIRCULAR
// Define At End Header Guard
# include "a.h"
# include "b.h"
#else
// Define At Beginning Header Guard
# include "ac.h"
# include "bc.h"
#endif
signed main () {
return(0);
}