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:
parent
6092c8d06c
commit
637c4d5d30
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
auto
|
||||||
|
chad.pdf
|
||||||
|
chad.log
|
||||||
|
chad.aux
|
||||||
|
*.out
|
||||||
|
*.o
|
8
chad.tex
8
chad.tex
@ -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.
|
||||||
|
8
reasoning/header-guard/README.md
Normal file
8
reasoning/header-guard/README.md
Normal 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.
|
10
reasoning/header-guard/a.h
Normal file
10
reasoning/header-guard/a.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef A_H
|
||||||
|
|
||||||
|
#include "b.h"
|
||||||
|
|
||||||
|
struct a {
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define A_H
|
||||||
|
#endif
|
10
reasoning/header-guard/ac.h
Normal file
10
reasoning/header-guard/ac.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef A_H
|
||||||
|
#define A_H
|
||||||
|
|
||||||
|
#include "bc.h"
|
||||||
|
|
||||||
|
struct a {
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
10
reasoning/header-guard/b.h
Normal file
10
reasoning/header-guard/b.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef B_H
|
||||||
|
|
||||||
|
#include "a.h"
|
||||||
|
|
||||||
|
struct b {
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define B_H
|
||||||
|
#endif
|
10
reasoning/header-guard/bc.h
Normal file
10
reasoning/header-guard/bc.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef B_H
|
||||||
|
#define B_H
|
||||||
|
|
||||||
|
#include "ac.h"
|
||||||
|
|
||||||
|
struct b {
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
19
reasoning/header-guard/main.c
Normal file
19
reasoning/header-guard/main.c
Normal 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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user