mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 17:00:05 +01:00
[SPCA] Fixes a few errors
This commit is contained in:
@@ -37,7 +37,7 @@ Very low precedence belongs to boolean operators \verb|&&| and \texttt{||}, as w
|
||||
\shade{blue}{Associativity}
|
||||
\begin{itemize}
|
||||
\item Left-to-right: $A + B + C \mapsto (A + B) + C$
|
||||
\item Right-to-left: \texttt{A += B += C} $\mapsto$ \texttt{(A += B) += C}
|
||||
\item Right-to-left: \texttt{A += B += C} $\mapsto$ \texttt{A += (B += C)}
|
||||
\end{itemize}
|
||||
|
||||
As it should be, boolean and, as well as boolean or, support early termination.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
\subsubsection{Integers in C}
|
||||
\label{sec:c-integers}
|
||||
As a reminder, integers are encoded as follows in big endian notation, with $x_i$ being the $i$-th bit and $w$ being the number of bits used to represent the number:
|
||||
\begin{itemize}[noitemsep]
|
||||
\item \bi{Unsigned}: $\displaystyle \sum_{i = 0}^{w - 1} x_i \cdot 2^i$
|
||||
|
||||
@@ -4,13 +4,20 @@ To have \texttt{gcc} stop compiliation after running through \texttt{cpp}, the \
|
||||
|
||||
\content{Imports} Imports in \lC\ are handled by the preprocessor, that for each \verb|#include <file1.h>|, the preprocessor simply copies the contents of the file recursively into one file. Note that this can easily lead to errors caused by multiple definitions. Using the \texttt{cpp} directive \verb|#ifndef| can be used to avoid this.
|
||||
|
||||
Depending on if we use \verb|#include <file1.h>| or \verb|#include "file1.h"| the preprocessor will search for the file either in the system headers or in the project directory.
|
||||
Depending on if we use \verb|#include <file1.h>| or \verb|#include "file1.h"| the preprocessor will search for the file either in the system headers
|
||||
(on Linux typically in \texttt{/usr/include/}) or in the project directory.
|
||||
Be wary of including files twice, as the preprocessor will recursively include all files (i.e. it will include files from the files we included)
|
||||
It is however possible to prevent that from becoming an issue using this (called an \texttt{include guard}):
|
||||
|
||||
\inputcodewithfilename{c}{}{code-examples/00_c/01_preprocessor/00_include-guards.h}
|
||||
|
||||
The name you pick for the preprocessor macro used in the check, by convention usually has the form \texttt{NAME\_H}.
|
||||
It should not start in an underscore (or multiple) and it should not contain more than one consecutive underscore.
|
||||
|
||||
The \lC\ preprocessor gives us what are called \texttt{preprocessor macros}, which have the format \verb|#define NAME SUBSTITUTION|.
|
||||
\rmvspace
|
||||
|
||||
\inputcodewithfilename{c}{}{code-examples/00_c/01_preprocessor/00_macros.c}
|
||||
\inputcodewithfilename{c}{}{code-examples/00_c/01_preprocessor/01_macros.c}
|
||||
|
||||
To avoid issues with semicolons at the end of preprocessor macros that wrap statements that cannot end in semicolons, we can use a concept called semicolon swallowing.
|
||||
For that, we wrap the statements in a \texttt{do \dots\ while(0)} loop, which is removed by the compiler on compile, also taking with it the semicolon.
|
||||
|
||||
Reference in New Issue
Block a user