[SPCA] Continue summary

This commit is contained in:
2026-01-06 10:52:34 +01:00
parent 74205e8cf0
commit 13e3210298
20 changed files with 79 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
\subsection{Basics}
\texttt{C} uses a very similar syntax as many other programming languages, like \texttt{Java}, \texttt{JavaScript} and many more\dots
to be precise, it is \textit{them} that use the \texttt{C} syntax, not the other way around. So:
\inputcodewithfilename{c}{code-examples/00_c/}{00_intro.c}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{00_intro.c}
In \texttt{C} we are referring to the implementation of a function as a \bi{(function) definition} (correspondingly, \textit{variable definition}, if the variable is initialized)
and to the definition of the function signature (or variables, without initializing them) as the \bi{(function) declaration} (or, correspondingly, \textit{variable declaration}).
@@ -9,4 +9,4 @@ and to the definition of the function signature (or variables, without initializ
\texttt{C} code is usuallt split into the source files, ending in \texttt{.c} (where the local functions and variables are declared, as well as all function definitions)
and the header files, ending in \texttt{.h}, usually sharing the filename of the source file, where the external declarations are defined.
By convention, no definition of functions are in the \texttt{.h} files, and neither variables, but there is nothing preventing you from putting them there.
\inputcodewithfilename{c}{code-examples/00_c/}{01_func.h}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{01_func.h}

View File

@@ -9,6 +9,6 @@ And because the labels are (as in Assembly) simply skipped over during execution
We can also use \texttt{continue} and \texttt{break} statements similarly to \texttt{Java}, they do not however accept labels.
(Reminder: \texttt{continue} skips the loop body and goes to the next iteration)
\inputcodewithfilename{c}{code-examples/00_c/}{01_func.c}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{01_func.c}

View File

@@ -2,7 +2,7 @@
\subsubsection{Declarations}
We have already seen a few examples for how \texttt{C} handles declarations.
In concept they are similar (and scoping works the same) to most other \texttt{C}-like programming languages, including \texttt{Java}.
\inputcodewithfilename{c}{code-examples/00_c/}{02_declarations.c}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{02_declarations.c}
A peculiarity of \texttt{C} is that the bit-count is not defined by the language, but rather the hardware it is compiled for.
\begin{fullTable}{llll}{\texttt{C} data type & typical 32-bit & ia32 & x86-64}{Comparison of byte-sizes for each datatype on different architectures}
@@ -35,3 +35,5 @@ Some will force a change of bit representation, but most won't (notably, when ca
Another important feature is that every \lC\ statement is also an expression, see above code block for example.
The \texttt{void} type has \bi{no} value and is used for untyped pointers and declaring functions with no return value
It is also possible to define a custom type using \texttt{typedef <type it represents> <name of the new type>}

View File

@@ -41,3 +41,5 @@ As previously touched on, every statement is also an expression, i.e. the follow
\mint{c}|printf("%s", x = foo(y)); // prints output of foo(y) and x has that value|
Pre-increment (\texttt{++i}, new value returned) and post-increment (\texttt{i++}, old value returned) are also supported by \lC.
\lC\ has an \texttt{assert} statement, but do not use it for error handling. The basic syntax is \texttt{assert( expr );}

View File

@@ -4,4 +4,4 @@
Unlike some other programming languages, arrays are \bi{not} dynamic length.
The below snippet includes already some pointer arithmetic tricks. The variable \texttt{data} is a pointer to the first element of the array.
\inputcodewithfilename{c}{code-examples/00_c/}{03_arrays.c}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{03_arrays.c}

View File

@@ -3,4 +3,4 @@
with length of the array $n + 1$ (where $n$ is the number of characters of the string).
The extra element is the termination character, called the \texttt{null character}, denoted \verb|\0|.
To determine the actual length of the string (as it may be padded), we can use \verb|strnlen(str, maxlen)| from \texttt{string.h}
\inputcodewithfilename{c}{code-examples/00_c/}{04_strings.c}
\inputcodewithfilename{c}{code-examples/00_c/00_basics/}{04_strings.c}

View File

@@ -0,0 +1,9 @@
\subsubsection{Integers in C}
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$
\item \bi{Signed}: $\displaystyle -x_{w - 1} \cdot 2^{w - 1} + \sum_{i = 0}^{w - 1} x_i \cdot 2^i$ (two's complement notation, with $x_{w - 1}$ being the sign-bit)
\end{itemize}
The minimum number representable is $0$ and $-2^{w - 1}$, respectively, whereas the maximum number representable is $2^w - 1$ and $2^{w - 1} - 1$
We can use the shift operators to multiply and divide by two. Shift operations are usually \textit{much} cheaper than multiplication and division.