[SPCA] Fix various errors

This commit is contained in:
2026-01-23 10:33:49 +01:00
parent b86fd00a60
commit 25b3381294
15 changed files with 36 additions and 23 deletions

View File

@@ -75,12 +75,12 @@ It is even possible to do this:
\rmvspace
\content{Namespaces}
\lC\ has a few different namespaces, i.e. you can have the one of the same name in each namespace (i.e. you can have \texttt{struct a}, \texttt{int a}, etc).
\lC\ has a few different namespaces, i.e. you can have one of the same name in each namespace (i.e. you can have \texttt{struct a}, \texttt{int a}, etc).
The following namespaces were covered:
\rmvspace
\begin{itemize}[noitemsep]
\item Label names (used for \texttt{goto})
\item Tags (for \texttt{struct}, \texttt{union} and \texttt{enum})
\item Member names one namespace for each \texttt{struct}, \texttt{union} and \texttt{enum}
\item Tags (for \texttt{struct}, \texttt{union} and \texttt{enum} names)
\item Member names (one namespace for each \texttt{struct}, \texttt{union} and \texttt{enum})
\item Everything else mostly (types, variable names, etc, including typedef)
\end{itemize}

View File

@@ -5,6 +5,12 @@ In Table \ref{tab:c-operators}, you can see an overview of the operators, sorted
You may notice that the \verb|&| and \verb|*| operators appear twice. The higher precedence occurrence is the address operator and dereference, respectively,
and the lower precedence is \texttt{bitwise and} and \texttt{multiplication}, respectively.
Additionally, \verb|+| and \verb|-| also appear twice, the higher precedence one being a unary plus or minus, respectively, which is used to denote positive or negative numbers,
and it can also be used to do a sort-of assertion that we have an arithmetic type using the preprocessor macro
\mint{c}|#define CHECK_ARITHMETIC(x) (+(x))|
which will cause a compiler error if \texttt{x} is for example a pointer.
Of course, the lower precedence \verb|+| and \verb|-| is addition and subtraction, respectively.
Very low precedence belongs to boolean operators \verb|&&| and \texttt{||}, as well as the ternary operator and assignment operators
\begin{table}[h!]
\begin{tables}{ll}{Operator & Associativity}
@@ -34,7 +40,7 @@ Very low precedence belongs to boolean operators \verb|&&| and \texttt{||}, as w
\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.
As it should be, boolean and, as well as boolean or, support early termination.
The ternary operator works as in other programming languages \verb|result = expr ? res_true : res_false;|

View File

@@ -4,7 +4,7 @@ On loading of a program, the OS creates the virtual address space for the proces
before other preparations like final linking and relocation are done.
Stack-based languages (supporting recursion) allocate stack in frames that contain local variables, return information and temporary space.
When a procedure is entered, a stack frame is allocated and executes any necessary setup code (like moving the stack pointer, see later). % TODO: Link to correct section
When a procedure is entered, a stack frame is allocated and executes any necessary setup code (like moving the stack pointer, see \ref{sec:asm-stack}).
When a procedure returns, the stack frame is deallocated and any necessary cleanup code is executed, before execution of the previous frame continues.
\bi{In \lC\ a pointer is a variable whose value is the memory address of another variable}
@@ -19,13 +19,15 @@ The (Linux)-Kernel randomizes the address space to prevent some common exploits.
\end{scriptsize}
\content{Pointer Arithmetic} Note that when doing pointer arithmetic, adding $1$ will move the pointer by \texttt{sizeof(type)} bits.
Pointer arithmetic with a \texttt{void} pointer is thus not allowed by standard \lC, as the compiler does not know the size of the data type.
However, \texttt{gcc} does allow it and assumes the size of \texttt{void} is \texttt{1 byte}.
You may use pointer arithmetic on whatever pointer you'd like (as long as it's not a null pointer).
This means, you \textit{can} make an array wherever in memory you'd like.
The issue is just that you are likely to overwrite something, and that something might be something critical (like a stack pointer),
thus you will get \bi{undefined} behaviour! (This is by the way a common concept in \lC, if something isn't easy to make more flexible
(example for \texttt{malloc}, if you pass a pointer to memory that is not the start of the \texttt{malloc}'d section, you get undefined behaviour),
in the docs mention that one gets undefined behaviour if you do not do as it says so\dots RTFM!)
in the docs mention that one gets undefined behaviour if you do not do as it says, so\dots RTFM!)
As already seen in the section arrays (section \ref{sec:c-arrays}), we can use pointer arithmetic for accessing array elements.
The array name is treated as a pointer to the first element of the array, except when:

View File

@@ -4,7 +4,7 @@ The advantage of having denormalized values is that 0 can be represented as the
\content{Example} $8$b Floating Point table to visualize the different cases.
$$
8\text{b precision Floating Point:}\quad \underbrace{0}_s \underbrace{0000}_c \underbrace{000}_m
8\text{b precision Floating Point:}\quad \underbrace{0}_s \underbrace{0000}_e \underbrace{000}_m
$$
\renewcommand{\arraystretch}{1.2}