Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f7424e4

Browse files
author
hengxin
committed
1-3-tromino-tiling: +overview, revision of 1d-array and 2d-array, +handout versoin
1 parent 3ad99a0 commit f7424e4

12 files changed

+80
-33
lines changed
133 KB
Binary file not shown.
9.76 KB
Binary file not shown.

‎tutorial/1-3-tromino-tiling/1-3-tromino-tiling.tex‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
\subtitle{--- \subtitletext}
88

99
\author[Hengfeng Wei]{\large 魏恒峰}
10-
\titlegraphic{\includegraphics[height = 2.0cm]{figs/qrcode-programming-tutorial.png}}
10+
%\titlegraphic{\includegraphics[height = 2.0cm]{figs/qrcode-programming-tutorial.png}}
1111
\institute{hfwei@nju.edu.cn}
12-
\date{2017年10月27日}
12+
\date{2017年11月03日}
1313

1414
\AtBeginSection[]{
1515
\begin{frame}[noframenumbering, plain]
@@ -22,7 +22,8 @@
2222

2323
\maketitle
2424

25-
\input{parts/1-2-review}
25+
\input{parts/overview}
26+
% \input{parts/1-2-review}
2627
\input{parts/memory}
2728
% \input{parts/recursion}
2829
% pointer-1d-array.tex, pointer-2d-array.tex
1.18 MB
Binary file not shown.
9.47 KB
Loading[フレーム]

‎tutorial/1-3-tromino-tiling/parts/memory.tex‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
\begin{frame}{}
99
\begin{definition}[Memory (K\&R)]
1010
The memory is organized as a collection of consecutively \red{addressed} cells
11-
that may be manipulated individually or in contiguous groups.
11+
that may be manipulated \blue{individually or in contiguous groups}.
1212
\end{definition}
1313

1414
\fignocaption{width = 0.60\textwidth}{figs/memory-cell}
@@ -18,20 +18,40 @@
1818
%%%%%%%%%%%%%%%
1919
\begin{frame}{}
2020
\fignocaption{width = 0.60\textwidth}{figs/program-memory-cplusplus}
21+
\vspace{-0.60cm}
22+
\centerline{Program Memory}
2123
\end{frame}
2224
%%%%%%%%%%%%%%%
2325

2426
%%%%%%%%%%%%%%%
25-
\begin{frame}{}
27+
\begin{frame}[fragile]{}
2628
\begin{table}
27-
\begin{tabular}{c|c|c}
29+
\centering
30+
\begin{adjustbox}{max width = \textwidth}
31+
\begin{tabular}{c|c|c|c}
2832
\hline
29-
Types & Scopes &Lifttimes \\ \hline
30-
Static/Global & The entire file & The lifetime of the program \\ \hline
31-
Automatic & & \\ \hline
32-
Dynamic & & \\ \hline
33+
{\bf Type} & {\bf Scope} & {\bf Lifttime} & {\bf Storage} \\ \hline \hline
34+
\blue{\it Global} & The entire file & The lifetime of the \blue{program} & .BSS/.DATA \\ \hline
35+
\blue{\it Static} & The \red{function} it is declared within & The lifetime of the \blue{program} & .BSS/.DATA \\ \hline
36+
\blue{\it Automatic} & The \red{function} it is declared within & While the \blue{function} is executing & Stack \\ \hline
37+
\blue{\it Dynamic} & \innercell{c}{Determined by the \red{pointers} \\ that reference this memory} & Until the memory is \blue{freed} & Heap \\ \hline
3338
\end{tabular}
39+
\end{adjustbox}
3440
\end{table}
41+
42+
\begin{lstlisting}[style = Cstyle]
43+
int a = 1; // global (inited)
44+
int b; // global (uninited)
45+
46+
int f(void) {
47+
int c = 0; // automatic (local)
48+
static int d = 0; // static (inited)
49+
d++;
50+
51+
int *p = malloc( sizeof(int) ); // dynamic
52+
free(p);
53+
}
54+
\end{lstlisting}
3555
\end{frame}
3656
%%%%%%%%%%%%%%%
3757

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%%%%%%%%%%%%%%%
2+
\begin{frame}[fragile]{}
3+
\begin{lstlisting}[style = Cstyle]
4+
int (*pa)[n] = malloc( sizeof(int[m][n]) );
5+
\end{lstlisting}
6+
7+
\pause
8+
\fignocaption{width = 0.25\textwidth}{figs/tiling-8-8}
9+
\end{frame}
10+
%%%%%%%%%%%%%%%
11+

‎tutorial/1-3-tromino-tiling/parts/pointer-1d-array.tex‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
\]
1515
\end{definition}
1616

17+
\vspace{0.40cm}
18+
\pause
19+
\centerline{\teal{\texttt{array-1d.c}}}
20+
21+
\vspace{0.40cm}
1722
\begin{lstlisting}[style = Cstyle]
1823
int a[5];
1924
a, $\quad$ &a[0] // what are they?
@@ -23,10 +28,6 @@
2328

2429
&a // what is this?
2530
\end{lstlisting}
26-
27-
\vspace{0.40cm}
28-
\pause
29-
\centerline{\teal{\texttt{array-1d.c}}}
3031
\end{frame}
3132
%%%%%%%%%%%%%%%
3233

@@ -35,7 +36,7 @@
3536
\begin{lstlisting}[style = Cstyle]
3637
int a[5];
3738

38-
int *pa;
39+
int *pa = a;
3940
\end{lstlisting}
4041

4142
\begin{definition}[Equivalence between Accesses]
@@ -63,8 +64,17 @@
6364
void f(int a[], int n);
6465
void f(int *a, int n);
6566

66-
f(a, 5);
67-
f(pa, 5);
67+
f(a, 5); // int a[5] = {0};
68+
69+
f(pa, 5); // int *pa = a;
70+
\end{lstlisting}
71+
72+
\begin{lstlisting}[style = Cstyle]
73+
int a[n];
74+
f(a, n);
75+
76+
int *pa = malloc( sizeof(int[n]) );
77+
f(pa, n);
6878
\end{lstlisting}
6979
\end{frame}
7080
%%%%%%%%%%%%%%%

‎tutorial/1-3-tromino-tiling/parts/pointer-2d-array.tex‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
\vspace{0.50cm}
5050
\pause
5151
\begin{lstlisting}[style = Cstyle]
52-
a[i][j]
52+
a[i][j] // *((*(a + i)) + j)
5353
\end{lstlisting}
5454
\end{frame}
5555
%%%%%%%%%%%%%%%
@@ -58,25 +58,27 @@
5858
\begin{frame}[fragile]{}
5959
\begin{lstlisting}[style = Cstyle]
6060
void f(int a[3][5]);
61-
6261
void f(int a[][5], int m); // m rows
63-
6462
void f(int (*a)[5], int m);
6563

66-
f(a, 3);
67-
f(pa, 3);
64+
f(a, 3); // int a[3][5];
65+
f(pa, 3); // int (*pa)[5] = a;
6866
\end{lstlisting}
67+
\end{frame}
68+
%%%%%%%%%%%%%%%
6969

70-
\pause
70+
%%%%%%%%%%%%%%%
71+
\begin{frame}[fragile]{}
7172
\begin{lstlisting}[style = Cstyle]
7273
void f(int m, int n, int a[m][n]);
73-
7474
void f(int m, int n, int a[][n]);
75-
7675
void f(int m, int n, int (*a)[n]);
7776

78-
f(3, 5, a);
79-
f(3, 5, pa);
77+
int a[m][n];
78+
f(m, n, a);
79+
80+
int (*pa)[n] = malloc( sizeof(int[m][n]) );
81+
f(m, n, pa);
8082
\end{lstlisting}
8183
\end{frame}
8284
%%%%%%%%%%%%%%%

‎tutorial/1-3-tromino-tiling/parts/pointers-arrays.tex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
\vspace{0.80cm}
66
\begin{quote}
7-
In C, there is a strong relationship between pointers and arrays,
7+
In C, there is a \red{strong relationship between pointers and arrays},
88
strong enough that pointers and arrays should be discussed simultaneously.
99

1010
\hfill --- K\&R

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /