mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-01-11 07:28:26 +00:00
[SPCA] Restructre, some notes
This commit is contained in:
@@ -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
|
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
|
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
|
||||||
}
|
}
|
||||||
@@ -25,12 +25,12 @@ int get_user_input_int( char prompt[] ) {
|
|||||||
|
|
||||||
while ( input_data > 1 ) {
|
while ( input_data > 1 ) {
|
||||||
input_data -= 1;
|
input_data -= 1;
|
||||||
printf( "Hello World" );
|
printf( "Hello World\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
input_data -= 1;
|
input_data -= 1;
|
||||||
printf( "Bye World" );
|
printf( "Bye World\n" );
|
||||||
} while ( input_data_copy > 1 );
|
} while ( input_data_copy > 1 );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
0
semester3/spca/code-examples/00_c/02_pointers.c
Normal file
0
semester3/spca/code-examples/00_c/02_pointers.c
Normal file
0
semester3/spca/code-examples/00_c/02_pointers.h
Normal file
0
semester3/spca/code-examples/00_c/02_pointers.h
Normal file
@@ -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,
|
\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.
|
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).
|
(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.
|
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.
|
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.
|
as lots of effort is put into the \texttt{C} compilers by the hardware manufacturers.
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
\subsection{The Syntax}
|
\subsection{The Syntax}
|
||||||
\texttt{C} uses a very similar syntax as many other programming languages, like \texttt{Java}, \texttt{JavaScript} and many more\dots
|
\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:
|
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/}{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}
|
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}
|
||||||
|
|||||||
Binary file not shown.
@@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
\setup{Systems Programming and Computer Architecture}
|
\setup{Systems Programming and Computer Architecture}
|
||||||
|
|
||||||
|
\usepackage{lmodern}
|
||||||
|
\setFontType{sans}
|
||||||
|
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\startDocument
|
\startDocument
|
||||||
\usetcolorboxes
|
\usetcolorboxes
|
||||||
|
|||||||
Reference in New Issue
Block a user