diff --git a/semester3/spca/code-examples/00_c/01_syntax/00_intro.c b/semester3/spca/code-examples/00_c/00_intro.c similarity index 88% rename from semester3/spca/code-examples/00_c/01_syntax/00_intro.c rename to semester3/spca/code-examples/00_c/00_intro.c index f503d99..7635eed 100644 --- a/semester3/spca/code-examples/00_c/01_syntax/00_intro.c +++ b/semester3/spca/code-examples/00_c/00_intro.c @@ -12,5 +12,5 @@ int main( int argc, char *argv[] ) { for ( int i = 0; i < argc; i++ ) // For loop just like any other sane programming language printf( "Arg %d: %s\n", i, argv[ i ] ); // Outputs the i-th argument from CLI - get_user_input_int( "Select a number" ); + get_user_input_int( "Select a number" ); // Function calls as in any other language } diff --git a/semester3/spca/code-examples/00_c/01_syntax/01_func.c b/semester3/spca/code-examples/00_c/01_func.c similarity index 92% rename from semester3/spca/code-examples/00_c/01_syntax/01_func.c rename to semester3/spca/code-examples/00_c/01_func.c index 63df54d..374e138 100644 --- a/semester3/spca/code-examples/00_c/01_syntax/01_func.c +++ b/semester3/spca/code-examples/00_c/01_func.c @@ -25,12 +25,12 @@ int get_user_input_int( char prompt[] ) { while ( input_data > 1 ) { input_data -= 1; - printf( "Hello World" ); + printf( "Hello World\n" ); } do { input_data -= 1; - printf( "Bye World" ); + printf( "Bye World\n" ); } while ( input_data_copy > 1 ); return 0; diff --git a/semester3/spca/code-examples/00_c/01_syntax/01_func.h b/semester3/spca/code-examples/00_c/01_func.h similarity index 100% rename from semester3/spca/code-examples/00_c/01_syntax/01_func.h rename to semester3/spca/code-examples/00_c/01_func.h diff --git a/semester3/spca/code-examples/00_c/02_pointers.c b/semester3/spca/code-examples/00_c/02_pointers.c new file mode 100644 index 0000000..e69de29 diff --git a/semester3/spca/code-examples/00_c/02_pointers.h b/semester3/spca/code-examples/00_c/02_pointers.h new file mode 100644 index 0000000..e69de29 diff --git a/semester3/spca/parts/00_c/00_intro.tex b/semester3/spca/parts/00_c/00_intro.tex index 7e75a14..2a4df05 100644 --- a/semester3/spca/parts/00_c/00_intro.tex +++ b/semester3/spca/parts/00_c/00_intro.tex @@ -1,13 +1,15 @@ -I can clearly C why you'd want to use C. Already sorry in advance for all the bad C jokes that are going to be part of this section +\begin{scriptsize} + \textit{I can clearly C why you'd want to use C. Already sorry in advance for all the bad C jokes that are going to be part of this section} +\end{scriptsize} \texttt{C} is a compiled, low-level programming language, lacking many features modern high-level programming languages offer, like Object Oriented programming, true Functional Programming (like Haskell implements), Garbage Collection, complex abstract datatypes and vectors, just to name a few. (It is possible to replicate these using Preprocessor macros, more on this later). -On the other hand, it offers the ability to directly integrate assembly code into the \texttt{.c} files, +On the other hand, it offers low-level hardware access, the ability to directly integrate assembly code into the \texttt{.c} files, as well as bit level data manipulation and extensive memory management options, again just to name a few. -This of course leads to \texttt{C} performing excellently and there are many programming languages who's compiler doesn't directly produce machine code or assembly, +This of course leads to \texttt{C} performing excellently and there are many programming languages whose compiler doesn't directly produce machine code or assembly, but instead optimized \texttt{C} code that is then compiled into machine code using a \texttt{C} compiler. -This has a number of benefits, most notably that \texttt{C} compilers can produce very efficient assembly, +This has a number of benefits, most notably that \texttt{C} compilers can produce very efficient assembly, as lots of effort is put into the \texttt{C} compilers by the hardware manufacturers. diff --git a/semester3/spca/parts/00_c/01_syntax.tex b/semester3/spca/parts/00_c/01_syntax.tex index 2193dba..0db7469 100644 --- a/semester3/spca/parts/00_c/01_syntax.tex +++ b/semester3/spca/parts/00_c/01_syntax.tex @@ -1,6 +1,13 @@ \subsection{The Syntax} \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/01_syntax/}{00_intro.c} -\inputcodewithfilename{c}{code-examples/00_c/01_syntax/}{01_func.h} -\inputcodewithfilename{c}{code-examples/00_c/01_syntax/}{01_func.c} +\inputcodewithfilename{c}{code-examples/00_c/}{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}). + +\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}, where the external declarations are defined. Usually, no definition of functions are in the \texttt{.h} files +\inputcodewithfilename{c}{code-examples/00_c/}{01_func.h} + +\inputcodewithfilename{c}{code-examples/00_c/}{01_func.c} diff --git a/semester3/spca/spca-summary.pdf b/semester3/spca/spca-summary.pdf index 4101d0b..00e78cf 100644 Binary files a/semester3/spca/spca-summary.pdf and b/semester3/spca/spca-summary.pdf differ diff --git a/semester3/spca/spca-summary.tex b/semester3/spca/spca-summary.tex index 916d125..e46a77a 100644 --- a/semester3/spca/spca-summary.tex +++ b/semester3/spca/spca-summary.tex @@ -4,6 +4,9 @@ \setup{Systems Programming and Computer Architecture} +\usepackage{lmodern} +\setFontType{sans} + \begin{document} \startDocument \usetcolorboxes