Skip to content
Snippets Groups Projects
Commit 85d4fa14 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Nachbereitung 26.11.2018

parent 00cdb194
Branches
No related tags found
No related merge requests found
Showing
with 525 additions and 10 deletions
......@@ -26,7 +26,7 @@ gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
int y = gap + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, width / 2, 10);
cairo_move_to (c, width / 2, gap);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
......
......@@ -2,5 +2,5 @@
int answer (void)
{
return 23;
return 42;
}
cassini/home/peter/bo/2018ws/hp/20181126> cat philosophy.c
#include <stdio.h>
#include "answer.h"
int main (void)
{
printf ("The answer is %d.\n", answer ());
return 0;
}
cassini/home/peter/bo/2018ws/hp/20181126> cat answer.h
extern int answer (void);
cassini/home/peter/bo/2018ws/hp/20181126> cat answer.c
#include "answer.h"
int answer (void)
{
return 23;
}
cassini/home/peter/bo/2018ws/hp/20181126> gcc -Wall -O philosophy.c -o philosophy
/tmp/ccnyOpK1.o: In function `main':
philosophy.c:(.text+0x5): undefined reference to `answer'
collect2: error: ld returned 1 exit status
cassini/home/peter/bo/2018ws/hp/20181126> gcc -Wall -O philosophy.c answer.c -o philosophy
cassini/home/peter/bo/2018ws/hp/20181126> ./philosophy
The answer is 23.
cassini/home/peter/bo/2018ws/hp/20181126> gcc -Wall -O philosophy.c -c
cassini/home/peter/bo/2018ws/hp/20181126> gcc -Wall -O answer.c -c
cassini/home/peter/bo/2018ws/hp/20181126> ls -l philosophy* answer.*
-rw-r--r-- 1 peter peter 56 Okt 25 2017 answer.c
-rw-r--r-- 1 peter peter 26 Okt 25 2017 answer.h
-rw-r--r-- 1 peter peter 1224 Nov 26 16:21 answer.o
-rwxr-xr-x 1 peter peter 8712 Nov 26 16:21 philosophy
-rw-r--r-- 1 peter peter 117 Okt 25 2017 philosophy.c
-rw-r--r-- 1 peter peter 1648 Nov 26 16:21 philosophy.o
cassini/home/peter/bo/2018ws/hp/20181126> gcc philosophy.o answer.o -o philosophy
cassini/home/peter/bo/2018ws/hp/20181126> ./philosophy
The answer is 23.
cassini/home/peter/bo/2018ws/hp/20181126>
#include <stdio.h>
double G = 6.67e-11;
int main (void)
{
printf ("G = %20.15lf\n", G);
return 0;
}
#include <stdio.h>
#include <math.h>
double G = 6.67 * pow (10, -11);
int main (void)
{
printf ("G = %20.15lf\n", G);
return 0;
}
#include <stdio.h>
#include <math.h>
double S2 = sqrt (2.0);
int main (void)
{
printf ("sqrt(2) = %20.15lf\n", S2);
return 0;
}
.file "const-functions-2.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "sqrt(2) = %20.15lf\n"
.text
.globl main
.type main, @function
main:
.LFB14:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movsd S2(%rip), %xmm0
leaq .LC0(%rip), %rdi
movl $1, %eax
call printf@PLT
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE14:
.size main, .-main
.globl S2
.data
.align 8
.type S2, @object
.size S2, 8
S2:
.long 1719614413
.long 1073127582
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
#include <math.h>
double square (double x)
{
return x * x;
}
double S2 = square (2.0);
int main (void)
{
printf ("2² = %20.15lf\n", S2);
return 0;
}
#include <stdio.h>
#include <math.h>
static inline double square (double x)
{
return x * x;
}
double S2 = square (2.0);
int main (void)
{
printf ("2² = %20.15lf\n", S2);
return 0;
}
No preview for this file type
......@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: make; Hardwarenahe Programmierung: Bit-Operationen, I/O-Ports
% README: make; Hardwarenahe Programmierung: Zahlensysteme, Bit-Operationen
\documentclass[10pt,t]{beamer}
......@@ -178,7 +178,7 @@
% \pause
\smallskip
\item
Mit \lstinline[style=cmd]{pkg-config --cflags --libs} erfährt man,\\
Mit \lstinline[style=cmd]{pkg-config --cflags --libs gtk+-3.0} erfährt man,\\
welche Optionen und Bibliotheken man an \lstinline[style=cmd]{gcc}
übergeben muß\alt<2->{.}{:}
% \pause
......@@ -224,8 +224,8 @@
\end{onlyenv}
\begin{onlyenv}<3->
\begin{lstlisting}[style=terminal,gobble=10]
$ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs)
-o hello-gtk¿
$ ¡gcc -Wall -O hello-gtk.c $(pkg-config --cflags --libs
gtk+-3.0) -o hello-gtk¿
\end{lstlisting}
\end{onlyenv}
\end{itemize}
......@@ -604,7 +604,6 @@
\end{frame}
\begin{frame}[fragile]
\showsubsubsection
......@@ -677,6 +676,8 @@
\end{frame}
\iffalse
\begin{frame}[fragile]
\showsubsubsection
......@@ -833,6 +834,8 @@
\end{frame}
\fi
\nosectionnonumber{\inserttitle}
\begin{frame}
......@@ -853,10 +856,10 @@
\end{itemize}
\item[\textbf{4}] \textbf{Hardwarenahe Programmierung}
\begin{itemize}
\color{medgreen}
\color{orange}
\item[4.1] Bit-Operationen
\item[4.2] I/O-Ports
\color{red}
\item[4.2] I/O-Ports
\item[4.3] Interrupts
\vspace*{-0.1cm}
\item[\dots]
......
#include <stdio.h>
int main (void)
{
printf ("The answer is: %d\n", 042);
return 0;
}
#include <gtk/gtk.h>
#include <math.h>
int width = 320;
int height = 240;
int gap = height / 20;
int r = gap;
double visual_length = height - 2 * gap - r;
double phi0 = -0.5;
double omega0 = 0.0;
double t0 = 0.0;
double g = 9.81;
double l = 1.0;
double dt = 0.02;
double t = t0;
double phi = phi0;
double omega = omega0;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
int x = width / 2 + visual_length * sin (phi);
int y = gap + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, width / 2, gap);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean timer (GtkWidget *widget)
{
t += dt;
phi += omega * dt;
omega += - dt * g / l * sin (phi);
gtk_widget_queue_draw_area (widget, 0, 0, width, height);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, width, height);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
#include <math.h>
int width = 320;
int height = 240;
int gap;
int r;
double visual_length;
double phi0 = -0.5;
double omega0 = 0.0;
double t0 = 0.0;
double g = 9.81;
double l = 1.0;
double dt = 0.02;
double t;
double phi;
double omega;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
int x = width / 2 + visual_length * sin (phi);
int y = gap + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, width / 2, 10);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean timer (GtkWidget *widget)
{
t += dt;
phi += omega * dt;
omega += - dt * g / l * sin (phi);
gtk_widget_queue_draw_area (widget, 0, 0, width, height);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gap = height / 20;
r = gap;
visual_length = height - 2 * gap - r;
t = t0;
phi = phi0;
omega = omega0;
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, width, height);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
#include <math.h>
#define WIDTH 320
#define HEIGHT 240
#define GAP (HEIGHT / 20)
#define r GAP
#define visual_length (HEIGHT - 2 * GAP - r)
#define phi0 (-0.5)
#define omega0 0.0
#define t0 0.0
#define g 9.81
#define l 1.0
#define dt 0.02
double t = t0;
double phi = phi0;
double omega = omega0;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
int x = WIDTH / 2 + visual_length * sin (phi);
int y = GAP + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, WIDTH / 2, 10);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean timer (GtkWidget *widget)
{
t += dt;
phi += omega * dt;
omega += - dt * g / l * sin (phi);
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
#include <math.h>
#define WIDTH 320
#define HEIGHT 240
#define GAP (HEIGHT / 20)
#define r GAP
#define visual_length (HEIGHT - 2 * GAP - r)
#define phi0 (-0.5)
#define omega0 0.0
#define t0 0.0
#define g 9.81
#define l 1.0
#define dt 0.02
double t = t0;
double phi = phi0;
double omega = omega0;
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA orange = { 1.0, 0.5, 0.0, 1.0 };
int x = WIDTH / 2 + visual_length * sin (phi);
int y = GAP + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, &orange);
cairo_move_to (c, WIDTH / 2, 10);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean timer (GtkWidget *widget)
{
t += dt;
phi += omega * dt;
omega += - dt * g / l * phi;
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
#include <math.h>
#define WIDTH 320
#define HEIGHT 240
#define GAP (HEIGHT / 20)
#define r GAP
#define visual_length (HEIGHT - 2 * GAP - r)
#define phi0 (-0.5)
#define omega0 0.0
#define t0 0.0
#define g 9.81
#define l 1.0
#define dt 0.02
double t = t0;
double phi_with_sin = phi0;
double omega_with_sin= omega0;
double phi_without_sin = phi0;
double omega_without_sin= omega0;
void draw_pendulum (cairo_t *c, double phi, GdkRGBA *colour)
{
int x = WIDTH / 2 + visual_length * sin (phi);
int y = GAP + visual_length * cos (phi);
gdk_cairo_set_source_rgba (c, colour);
cairo_move_to (c, WIDTH / 2, 10);
cairo_line_to (c, x, y);
cairo_stroke (c);
cairo_arc (c, x, y, r, 0, 2 * G_PI);
cairo_fill (c);
}
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA blue = { 0.0, 0.5, 1.0, 1.0 };
GdkRGBA orange = { 1.0, 0.5, 0.0, 1.0 };
GdkRGBA green = { 0.0, 0.5, 0.0, 1.0 };
double A = phi0;
double B = 0.5 * M_PI; /* 90° */
double phi_analytic = A * sin (sqrt (g / l) * t + B);
draw_pendulum (c, phi_with_sin, &blue);
draw_pendulum (c, phi_without_sin, &orange);
draw_pendulum (c, phi_analytic, &green);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
gboolean timer (GtkWidget *widget)
{
t += dt;
phi_with_sin += omega_with_sin * dt;
omega_with_sin += - dt * g / l * sin (phi_with_sin);
phi_without_sin += omega_without_sin * dt;
omega_without_sin += - dt * g / l * phi_without_sin;
gtk_widget_queue_draw_area (widget, 0, 0, WIDTH, HEIGHT);
g_timeout_add (50, (GSourceFunc) timer, widget);
return FALSE;
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_widget_show (drawing_area);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_size_request (drawing_area, WIDTH, HEIGHT);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
g_timeout_add (50, (GSourceFunc) timer, drawing_area);
gtk_main ();
return 0;
}
20181126/photo-20181126-174025.jpg

150 KiB

README: Prakikumstermine, Bit-Operationen
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment