diff --git a/20190113/aufgabe-1.c b/20190114/aufgabe-1.c similarity index 100% rename from 20190113/aufgabe-1.c rename to 20190114/aufgabe-1.c diff --git a/20190113/aufgabe-2a.c b/20190114/aufgabe-2a.c similarity index 100% rename from 20190113/aufgabe-2a.c rename to 20190114/aufgabe-2a.c diff --git a/20190113/aufgabe-2b.c b/20190114/aufgabe-2b.c similarity index 100% rename from 20190113/aufgabe-2b.c rename to 20190114/aufgabe-2b.c diff --git a/20190113/gtk-1.c b/20190114/gtk-1.c similarity index 100% rename from 20190113/gtk-1.c rename to 20190114/gtk-1.c diff --git a/20190113/gtk-2.c b/20190114/gtk-2.c similarity index 100% rename from 20190113/gtk-2.c rename to 20190114/gtk-2.c diff --git a/20190113/gtk-3.c b/20190114/gtk-3.c similarity index 100% rename from 20190113/gtk-3.c rename to 20190114/gtk-3.c diff --git a/20190113/gtk-4.c b/20190114/gtk-4.c similarity index 100% rename from 20190113/gtk-4.c rename to 20190114/gtk-4.c diff --git a/20190113/gtk-5.c b/20190114/gtk-5.c similarity index 100% rename from 20190113/gtk-5.c rename to 20190114/gtk-5.c diff --git a/20190113/gtk-6.c b/20190114/gtk-6.c similarity index 100% rename from 20190113/gtk-6.c rename to 20190114/gtk-6.c diff --git a/20190113/gtk-7.c b/20190114/gtk-7.c similarity index 100% rename from 20190113/gtk-7.c rename to 20190114/gtk-7.c diff --git a/20190113/hello-gtk.png b/20190114/hello-gtk.png similarity index 100% rename from 20190113/hello-gtk.png rename to 20190114/hello-gtk.png diff --git a/20190113/hp-20190113.pdf b/20190114/hp-20190114.pdf similarity index 99% rename from 20190113/hp-20190113.pdf rename to 20190114/hp-20190114.pdf index 61094c4e509d8476b726fd88e37282b6f554c4c8..53f9bc52c5687b45d79c284131d8edfd10d46db8 100644 Binary files a/20190113/hp-20190113.pdf and b/20190114/hp-20190114.pdf differ diff --git a/20190113/hp-20190113.tex b/20190114/hp-20190114.tex similarity index 99% rename from 20190113/hp-20190113.tex rename to 20190114/hp-20190114.tex index c176e5f0939b5be11bae1255b258c6d2d72bc341..96c446e9e544262ba21fb42b2f07d2eb3133b8c5 100644 --- a/20190113/hp-20190113.tex +++ b/20190114/hp-20190114.tex @@ -1,4 +1,4 @@ -% hp-20190113.pdf - Lecture Slides on Low-Level Programming +% hp-20190114.pdf - Lecture Slides on Low-Level Programming % Copyright (C) 2012, 2013, 2015, 2016, 2017, 2018, 2019 Peter Gerwinski % % This document is free software: you can redistribute it and/or @@ -40,7 +40,7 @@ \title{Hardwarenahe Programmierung} \author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski} -\date{13.\ Januar 2019} +\date{14.\ Januar 2019} \begin{document} diff --git a/20190113/hp-uebung-20190113.pdf b/20190114/hp-uebung-20190114.pdf similarity index 72% rename from 20190113/hp-uebung-20190113.pdf rename to 20190114/hp-uebung-20190114.pdf index 3bdbdd519681e19b5e3134efa85b0deb6f702f9e..15929343d34703283c19a9ed6a786e52409b5449 100644 Binary files a/20190113/hp-uebung-20190113.pdf and b/20190114/hp-uebung-20190114.pdf differ diff --git a/20190113/hp-uebung-20190113.tex b/20190114/hp-uebung-20190114.tex similarity index 96% rename from 20190113/hp-uebung-20190113.tex rename to 20190114/hp-uebung-20190114.tex index aa4f3f9dfccd271c7259103c8eb96a2ab26fb411..6153f359c39b6411c0cc09084a154031c160afdc 100644 --- a/20190113/hp-uebung-20190113.tex +++ b/20190114/hp-uebung-20190114.tex @@ -1,4 +1,4 @@ -% hp-uebung-20190113.pdf - Exercises on Low-Level Programming / Applied Computer Sciences +% hp-uebung-20190114.pdf - Exercises on Low-Level Programming / Applied Computer Sciences % Copyright (C) 2013, 2015, 2016, 2017, 2018, 2019 Peter Gerwinski % % This document is free software: you can redistribute it and/or @@ -31,7 +31,7 @@ % \thispagestyle{empty} \section*{Hardwarenahe Programmierung\\ - Übungsaufgaben -- 13.\ Januar 2019} + Übungsaufgaben -- 14.\ Januar 2019} Diese Übung enthält Punkteangaben wie in einer Klausur. Um zu "`bestehen"', müssen Sie innerhalb von 90 Minuten @@ -40,7 +40,7 @@ \exercise{Iterationsfunktionen} - Wir betrachten das folgende Programm (\gitfile{hp}{20190113}{aufgabe-1.c}): + Wir betrachten das folgende Programm (\gitfile{hp}{20190114}{aufgabe-1.c}): \begin{minipage}[t]{0.4\textwidth} \begin{lstlisting}[gobble=6] @@ -86,7 +86,7 @@ \exercise{Objektorientierte Tier-Datenbank} - Das auf der nächsten Seite in Blau dargestellte Programm (Datei: \gitfile{hp}{20190113}{aufgabe-2a.c})\\ + Das auf der nächsten Seite in Blau dargestellte Programm (Datei: \gitfile{hp}{20190114}{aufgabe-2a.c})\\ soll Daten von Tieren verwalten. Beim Compilieren erscheinen die folgende Fehlermeldungen: @@ -98,7 +98,7 @@ \end{lstlisting} Der Programmierer nimmt die auf der nächsten Seite in Rot dargestellten Ersetzungen vor\\ - (Datei: \gitfile{hp}{20190113}{aufgabe-2b.c}). + (Datei: \gitfile{hp}{20190114}{aufgabe-2b.c}). Daraufhin gelingt das Compilieren, und die Ausgabe des Programms lautet: \begin{lstlisting}[style=terminal] $ ¡gcc -std=c99 -Wall -O aufgabe-2b.c -o aufgabe-2b¿ diff --git a/20190113/landau-symbols-2.pdf b/20190114/landau-symbols-2.pdf similarity index 100% rename from 20190113/landau-symbols-2.pdf rename to 20190114/landau-symbols-2.pdf diff --git a/20190113/landau-symbols.pdf b/20190114/landau-symbols.pdf similarity index 100% rename from 20190113/landau-symbols.pdf rename to 20190114/landau-symbols.pdf diff --git a/20190113/logo-hochschule-bochum-cvh-text-v2.pdf b/20190114/logo-hochschule-bochum-cvh-text-v2.pdf similarity index 100% rename from 20190113/logo-hochschule-bochum-cvh-text-v2.pdf rename to 20190114/logo-hochschule-bochum-cvh-text-v2.pdf diff --git a/20190113/logo-hochschule-bochum.pdf b/20190114/logo-hochschule-bochum.pdf similarity index 100% rename from 20190113/logo-hochschule-bochum.pdf rename to 20190114/logo-hochschule-bochum.pdf diff --git a/20190114/nodynmem-1.c b/20190114/nodynmem-1.c new file mode 100644 index 0000000000000000000000000000000000000000..5ab686fa1e2c6f5c40078eb99d4e57fb7589507f --- /dev/null +++ b/20190114/nodynmem-1.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int main (void) +{ + char *name[] = { "Anton", "Bertha", "Cäsar" }; + + char *new_name[4]; + for (int i = 0; i < 3; i++) + new_name[i] = name[i]; + new_name[3] = "Dieter"; + + return 0; +} diff --git a/20190114/nodynmem-2.c b/20190114/nodynmem-2.c new file mode 100644 index 0000000000000000000000000000000000000000..0edbf930fc7fdabcdd97ee27adfc429bda2549c2 --- /dev/null +++ b/20190114/nodynmem-2.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +char *name[] = { "Anton", "Bertha", "Cäsar" }; + +void store_new_name (char *s) +{ + char *new_name[4]; + for (int i = 0; i < 3; i++) + new_name[i] = name[i]; + new_name[3] = s; +} + +int main (void) +{ + store_new_name ("Dieter"); + return 0; +} diff --git a/20190113/objects-1.c b/20190114/objects-1.c similarity index 100% rename from 20190113/objects-1.c rename to 20190114/objects-1.c diff --git a/20190114/objects-10.c b/20190114/objects-10.c new file mode 100644 index 0000000000000000000000000000000000000000..ac47c0ed5479be655b7d76aba558526b2dc774a3 --- /dev/null +++ b/20190114/objects-10.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <stdlib.h> + +#define T_BASE 0 +#define T_INTEGER 1 +#define T_STRING 2 + +typedef struct +{ + int type; + void (* print) (t_object *this); +} t_base; + +typedef struct +{ + int type; + void (* print) (t_object *this); + int content; +} t_integer; + +typedef struct +{ + int type; + void (* print) (t_object *this); + char *content; +} t_string; + +typedef union +{ + t_base base; + t_integer integer; + t_string string; +} t_object; + +void print_integer (t_object *this) +{ + printf ("Integer: %d\n", this->integer.content); +} + +void print_string (t_object *this) +{ + printf ("String: \"%s\"\n", this->string.content); +} + +t_object *new_integer (int i) +{ + t_object *p = malloc (sizeof (t_integer)); + p->integer.type = T_INTEGER; + p->integer.print = print_integer; + p->integer.content = i; + return p; +} + +t_object *new_string (char *s) +{ + t_object *p = malloc (sizeof (t_string)); + p->string.type = T_STRING; + p->string.print = print_string; + p->string.content = s; + return p; +} + +int main (void) +{ + t_object *object[] = { new_integer (42), + new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + object[i]->base.print (object[i]); + + return 0; +} diff --git a/20190114/objects-11.c b/20190114/objects-11.c new file mode 100644 index 0000000000000000000000000000000000000000..a15c8eb239b2315845f24f3b4f111d3670d7ea33 --- /dev/null +++ b/20190114/objects-11.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <stdlib.h> + +#define T_BASE 0 +#define T_INTEGER 1 +#define T_STRING 2 + +union t_object; + +typedef struct +{ + int type; + void (* print) (union t_object *this); +} t_base; + +typedef struct +{ + int type; + void (* print) (union t_object *this); + int content; +} t_integer; + +typedef struct +{ + int type; + void (* print) (union t_object *this); + char *content; +} t_string; + +typedef union t_object +{ + t_base base; + t_integer integer; + t_string string; +} t_object; + +void print_integer (t_object *this) +{ + printf ("Integer: %d\n", this->integer.content); +} + +void print_string (t_object *this) +{ + printf ("String: \"%s\"\n", this->string.content); +} + +t_object *new_integer (int i) +{ + t_object *p = malloc (sizeof (t_integer)); + p->integer.type = T_INTEGER; + p->integer.print = print_integer; + p->integer.content = i; + return p; +} + +t_object *new_string (char *s) +{ + t_object *p = malloc (sizeof (t_string)); + p->string.type = T_STRING; + p->string.print = print_string; + p->string.content = s; + return p; +} + +int main (void) +{ + t_object *object[] = { new_integer (42), + new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + object[i]->base.print (object[i]); + + return 0; +} diff --git a/20190114/objects-12.c b/20190114/objects-12.c new file mode 100644 index 0000000000000000000000000000000000000000..5d605e1b295e252b2d947a1d4ac04c9fc805d36d --- /dev/null +++ b/20190114/objects-12.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdlib.h> + +union t_object; + +typedef struct +{ + void (* print) (union t_object *this); +} t_base; + +typedef struct +{ + void (* print) (union t_object *this); + int content; +} t_integer; + +typedef struct +{ + void (* print) (union t_object *this); + char *content; +} t_string; + +typedef union t_object +{ + t_base base; + t_integer integer; + t_string string; +} t_object; + +void print_integer (t_object *this) +{ + printf ("Integer: %d\n", this->integer.content); +} + +void print_string (t_object *this) +{ + printf ("String: \"%s\"\n", this->string.content); +} + +t_object *new_integer (int i) +{ + t_object *p = malloc (sizeof (t_integer)); + p->integer.print = print_integer; + p->integer.content = i; + return p; +} + +t_object *new_string (char *s) +{ + t_object *p = malloc (sizeof (t_string)); + p->string.print = print_string; + p->string.content = s; + return p; +} + +int main (void) +{ + t_object *object[] = { new_integer (42), + new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + object[i]->base.print (object[i]); + + return 0; +} diff --git a/20190114/objects-13.c b/20190114/objects-13.c new file mode 100644 index 0000000000000000000000000000000000000000..81ef279b060e0b6290194fdeda8c3330cb716cdd --- /dev/null +++ b/20190114/objects-13.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <stdlib.h> + +union t_object; +struct t_vmt; + +typedef struct +{ + struct t_vmt *vmt; +} t_base; + +typedef struct +{ + struct t_vmt *vmt; + int content; +} t_integer; + +typedef struct +{ + struct t_vmt *vmt; + char *content; +} t_string; + +typedef union t_object +{ + t_base base; + t_integer integer; + t_string string; +} t_object; + +typedef struct t_vmt +{ + void (* print) (union t_object *this); +} t_vmt; + +void print_integer (t_object *this) +{ + printf ("Integer: %d\n", this->integer.content); +} + +void print_string (t_object *this) +{ + printf ("String: \"%s\"\n", this->string.content); +} + +t_vmt vmt_integer = { print_integer }; +t_vmt vmt_string = { print_string }; + +t_object *new_integer (int i) +{ + t_object *p = malloc (sizeof (t_integer)); + p->integer.vmt = &vmt_integer; + p->integer.content = i; + return p; +} + +t_object *new_string (char *s) +{ + t_object *p = malloc (sizeof (t_string)); + p->integer.vmt = &vmt_string; + p->string.content = s; + return p; +} + +int main (void) +{ + t_object *object[] = { new_integer (42), + new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + object[i]->base.vmt->print (object[i]); + + return 0; +} diff --git a/20190114/objects-14.cpp b/20190114/objects-14.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1c8c4aa93211f37429278ef142c818399f4ca811 --- /dev/null +++ b/20190114/objects-14.cpp @@ -0,0 +1,57 @@ +#include <stdio.h> + +struct TBase +{ + virtual void print (); +}; + +struct TInteger: TBase +{ + int content; + virtual void print (); + TInteger (int i); +}; + +struct TString: TBase +{ + const char *content; + virtual void print (); + TString (const char *s); +}; + +void TBase::print () +{ + printf ("Base\n"); +} + +void TInteger::print () +{ + printf ("Integer: %d\n", content); +} + +void TString::print () +{ + printf ("String: \"%s\"\n", content); +} + +TInteger::TInteger (int i) +{ + content = i; +} + +TString::TString (const char *s) +{ + content = s; +} + +int main (void) +{ + TBase *object[] = { new TInteger (42), + new TString ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + object[i]->print (); + + return 0; +} diff --git a/20190113/objects-2.c b/20190114/objects-2.c similarity index 100% rename from 20190113/objects-2.c rename to 20190114/objects-2.c diff --git a/20190113/objects-3.c b/20190114/objects-3.c similarity index 100% rename from 20190113/objects-3.c rename to 20190114/objects-3.c diff --git a/20190113/objects-4.c b/20190114/objects-4.c similarity index 100% rename from 20190113/objects-4.c rename to 20190114/objects-4.c diff --git a/20190113/objects-5.c b/20190114/objects-5.c similarity index 100% rename from 20190113/objects-5.c rename to 20190114/objects-5.c diff --git a/20190113/objects-6.c b/20190114/objects-6.c similarity index 100% rename from 20190113/objects-6.c rename to 20190114/objects-6.c diff --git a/20190114/objects-7.c b/20190114/objects-7.c new file mode 100644 index 0000000000000000000000000000000000000000..b9b24ad65f650aeda194e4570ae853e1a5ad8f11 --- /dev/null +++ b/20190114/objects-7.c @@ -0,0 +1,43 @@ +#include <stdio.h> + +#define T_BASE 0 +#define T_INTEGER 1 +#define T_STRING 2 + +typedef struct +{ + int type; +} t_base; + +typedef struct +{ + int type; + int content; +} t_integer; + +typedef struct +{ + int type; + char *content; +} t_string; + +void print_object (t_base *this) +{ + if (this->type == T_INTEGER) + printf ("Integer: %d\n", ((t_integer *) this)->content); + else if (this->type == T_STRING) + printf ("String: \"%s\"\n", ((t_string *) this)->content); +} + +int main (void) +{ + t_integer i = { T_INTEGER, 42 }; + t_string s = { T_STRING, "Hello, world!" }; + + t_base *object[] = { (t_base *) &i, (t_base *) &s, NULL }; + + for (int i = 0; object[i]; i++) + print_object (object[i]); + + return 0; +} diff --git a/20190114/objects-8.c b/20190114/objects-8.c new file mode 100644 index 0000000000000000000000000000000000000000..0c93e8f6c3c4b5e504c758dfa87b8510e98c0692 --- /dev/null +++ b/20190114/objects-8.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> + +#define T_BASE 0 +#define T_INTEGER 1 +#define T_STRING 2 + +typedef struct +{ + int type; +} t_base; + +typedef struct +{ + int type; + int content; +} t_integer; + +typedef struct +{ + int type; + char *content; +} t_string; + +void print_object (t_base *this) +{ + if (this->type == T_INTEGER) + printf ("Integer: %d\n", ((t_integer *) this)->content); + else if (this->type == T_STRING) + printf ("String: \"%s\"\n", ((t_string *) this)->content); +} + +t_integer *new_integer (int i) +{ + t_integer *p = malloc (sizeof (t_integer)); + p->type = T_INTEGER; + p->content = i; + return p; +} + +t_string *new_string (char *s) +{ + t_string *p = malloc (sizeof (t_string)); + p->type = T_STRING; + p->content = s; + return p; +} + +int main (void) +{ + t_base *object[] = { (t_base *) new_integer (42), + (t_base *) new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + print_object (object[i]); + + return 0; +} diff --git a/20190114/objects-9.c b/20190114/objects-9.c new file mode 100644 index 0000000000000000000000000000000000000000..41468b043cd69b1c19b2c4456eb937ff34dbe9f8 --- /dev/null +++ b/20190114/objects-9.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdlib.h> + +#define T_BASE 0 +#define T_INTEGER 1 +#define T_STRING 2 + +typedef struct +{ + int type; +} t_base; + +typedef struct +{ + int type; + int content; +} t_integer; + +typedef struct +{ + int type; + char *content; +} t_string; + +typedef union +{ + t_base base; + t_integer integer; + t_string string; +} t_object; + +void print_object (t_object *this) +{ + if (this->base.type == T_INTEGER) + printf ("Integer: %d\n", this->integer.content); + else if (this->base.type == T_STRING) + printf ("String: \"%s\"\n", this->string.content); +} + +t_object *new_integer (int i) +{ + t_object *p = malloc (sizeof (t_integer)); + p->integer.type = T_INTEGER; + p->integer.content = i; + return p; +} + +t_object *new_string (char *s) +{ + t_object *p = malloc (sizeof (t_string)); + p->string.type = T_STRING; + p->string.content = s; + return p; +} + +int main (void) +{ + t_object *object[] = { new_integer (42), + new_string ("Hello, world!"), + NULL }; + + for (int i = 0; object[i]; i++) + print_object (object[i]); + + return 0; +} diff --git a/20190113/pgscript.sty b/20190114/pgscript.sty similarity index 100% rename from 20190113/pgscript.sty rename to 20190114/pgscript.sty diff --git a/20190113/pgslides.sty b/20190114/pgslides.sty similarity index 100% rename from 20190113/pgslides.sty rename to 20190114/pgslides.sty diff --git a/20190114/unions-1.c b/20190114/unions-1.c new file mode 100644 index 0000000000000000000000000000000000000000..b75a6063b50193e13e9a2fd0ce140db6a8827499 --- /dev/null +++ b/20190114/unions-1.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdint.h> + +typedef union +{ + int8_t i; + uint8_t u; +} num8_t; + +int main (void) +{ + num8_t test; + test.i = -1; + printf ("%d\n", test.u); + return 0; +} diff --git a/20190114/unions-2.c b/20190114/unions-2.c new file mode 100644 index 0000000000000000000000000000000000000000..be8562a50395e50e007dc1c0b19b98a476935670 --- /dev/null +++ b/20190114/unions-2.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <stdint.h> + +typedef union +{ + char s[8]; + uint64_t x; +} num_char_t; + +int main (void) +{ + num_char_t test = { "Hello!" }; + printf ("%lx\n", test.x); + return 0; +}