diff --git a/talk/basicconcepts/arrayspointers.tex b/talk/basicconcepts/arrayspointers.tex index 5cc2d69b..7a6c4edd 100644 --- a/talk/basicconcepts/arrayspointers.tex +++ b/talk/basicconcepts/arrayspointers.tex @@ -16,7 +16,14 @@ \end{cppcode} \end{frame} -\Scontents*[store-cmd=code_arrays]{ +\begin{frame}[fragile] + \frametitlecpp[98]{Pointers} + \begin{multicols}{2} + % the code has to be repeated n times here. Anyone finding a better solution + % is welcome, but it's not a trivial task, due to the verbatim nature of minted + \begin{overprint}[\columnwidth] + \onslide<1> + \begin{minted}[linenos]{cpp} int i = 4; int *pi = &i; int j = *pi + 1; @@ -32,20 +39,151 @@ // seg fault ! int *pak = (int*)k; int l = *pak; -} -\begin{frame}[fragile] - \frametitlecpp[98]{Pointers} - \begin{multicols}{2} - \begin{overprint}[\columnwidth] - \onslide<1> \highlightCppCode{}{code_arrays} - \onslide<2> \highlightCppCode{1}{code_arrays} - \onslide<3> \highlightCppCode{2}{code_arrays} - \onslide<4> \highlightCppCode{3}{code_arrays} - \onslide<5> \highlightCppCode{5}{code_arrays} - \onslide<6> \highlightCppCode{6}{code_arrays} - \onslide<7> \highlightCppCode{7}{code_arrays} - \onslide<8> \highlightCppCode{8}{code_arrays} - \onslide<9> \highlightCppCode{11}{code_arrays} + \end{minted} + \onslide<2> + \begin{minted}[linenos,highlightlines=1]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<3> + \begin{minted}[linenos,highlightlines=2]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<4> + \begin{minted}[linenos,highlightlines=3]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<5> + \begin{minted}[linenos,highlightlines=5]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<6> + \begin{minted}[linenos,highlightlines=6]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<7> + \begin{minted}[linenos,highlightlines=7]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<8> + \begin{minted}[linenos,highlightlines=8]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} + \onslide<9> + \begin{minted}[linenos,highlightlines=11]{cpp} +int i = 4; +int *pi = &i; +int j = *pi + 1; + +int ai[] = {1,2,3}; +int *pai = ai; // decay to ptr +int *paj = pai + 1; +int k = *paj + 1; + +// compile error +int *pak = k; + +// seg fault ! +int *pak = (int*)k; +int l = *pak; + \end{minted} \end{overprint} \columnbreak \onslide<2->{ diff --git a/talk/basicconcepts/functions.tex b/talk/basicconcepts/functions.tex index 218a6e72..24ea9f40 100644 --- a/talk/basicconcepts/functions.tex +++ b/talk/basicconcepts/functions.tex @@ -69,7 +69,14 @@ \end{frame} -\Scontents*[store-cmd=code_bigStruct]{ +\begin{frame}[fragile] + \frametitlecpp[98]{Functions: parameters are passed by value} + \begin{multicols}{2} + % the code has to be repeated n times here. Anyone finding a better solution + % is welcome, but it's not a trivial task, due to the verbatim nature of minted + \begin{overprint}[\columnwidth] + \onslide<1-2> + \begin{minted}[linenos,highlightlines=2]{cpp} struct BigStruct {...}; BigStruct s; @@ -84,17 +91,41 @@ ... } printRef(s); // no copy -} -\begin{frame}[fragile] - \frametitlecpp[98]{Functions: parameters are passed by value} - \begin{multicols}{2} - \begin{overprint}[\columnwidth] - \onslide<1-2> - \highlightCppCode{2}{code_bigStruct} + \end{minted} \onslide<3> - \highlightCppCode{5,8}{code_bigStruct} + \begin{minted}[linenos,highlightlines={5,8}]{cpp} +struct BigStruct {...}; +BigStruct s; + +// parameter by value +void printVal(BigStruct p) { + ... +} +printVal(s); // copy + +// parameter by reference +void printRef(BigStruct &q) { + ... +} +printRef(s); // no copy + \end{minted} \onslide<4-> - \highlightCppCode{11,14}{code_bigStruct} + \begin{minted}[linenos,highlightlines={11,14}]{cpp} +struct BigStruct {...}; +BigStruct s; + +// parameter by value +void printVal(BigStruct p) { + ... +} +printVal(s); // copy + +// parameter by reference +void printRef(BigStruct &q) { + ... +} +printRef(s); // no copy + \end{minted} \end{overprint} \columnbreak \null \vfill @@ -121,7 +152,14 @@ \end{multicols} \end{frame} -\Scontents*[store-cmd=code_smallStruct]{ +\begin{frame}[fragile] + \frametitlecpp[98]{Functions: pass by value or reference?} + \begin{multicols}{2} + % the code has to be repeated n times here. Anyone finding a better solution + % is welcome, but it's not a trivial task, due to the verbatim nature of minted + \begin{overprint}[\columnwidth] + \onslide<1> + \begin{minted}[linenos]{cpp} struct SmallStruct {int a;}; SmallStruct s = {1}; @@ -136,27 +174,126 @@ } changeRef(s); // s.a == 2 -} -\begin{frame}[fragile] - \frametitlecpp[98]{Functions: pass by value or reference?} - \begin{multicols}{2} - \begin{overprint}[\columnwidth] - \onslide<1> - \highlightCppCode{}{code_smallStruct} + \end{minted} \onslide<2> - \highlightCppCode{2}{code_smallStruct} + \begin{minted}[linenos,highlightlines=2]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<3> - \highlightCppCode{4,7}{code_smallStruct} + \begin{minted}[linenos,highlightlines={4,7}]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<4> - \highlightCppCode{5}{code_smallStruct} + \begin{minted}[linenos,highlightlines=5]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<5> - \highlightCppCode{8}{code_smallStruct} + \begin{minted}[linenos,highlightlines=8]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<6> - \highlightCppCode{10,13}{code_smallStruct} + \begin{minted}[linenos,highlightlines={10,13}]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<7> - \highlightCppCode{11}{code_smallStruct} + \begin{minted}[linenos,highlightlines=11]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \onslide<8> - \highlightCppCode{14}{code_smallStruct} + \begin{minted}[linenos,highlightlines=14]{cpp} +struct SmallStruct {int a;}; +SmallStruct s = {1}; + +void changeVal(SmallStruct p) { + p.a = 2; +} +changeVal(s); +// s.a == 1 + +void changeRef(SmallStruct &q) { + q.a = 2; +} +changeRef(s); +// s.a == 2 + \end{minted} \end{overprint} \columnbreak \null \vfill diff --git a/talk/basicconcepts/scopesnamespaces.tex b/talk/basicconcepts/scopesnamespaces.tex index d3995b79..a9abfab5 100644 --- a/talk/basicconcepts/scopesnamespaces.tex +++ b/talk/basicconcepts/scopesnamespaces.tex @@ -21,15 +21,6 @@ \end{exampleblock} \end{frame} -\Scontents*[store-cmd=code_scopes]{ -int a = 1; -{ - int b[4]; - b[0] = a; -} -// Doesn't compile here: -// b[1] = a + 1; -} \begin{frame}[fragile] \frametitlecpp[98]{Scope and lifetime of variables} \begin{block}{Variable life time} @@ -45,15 +36,49 @@ \end{itemize} \end{goodpractice} \begin{multicols}{2} + % the code has to be repeated n times here. Anyone finding a better solution + % is welcome, but it's not a trivial task, due to the verbatim nature of minted \begin{overprint}[\columnwidth] \onslide<1> - \highlightCppCode{1}{code_scopes} + \begin{minted}[linenos,highlightlines=1]{cpp} +int a = 1; +{ + int b[4]; + b[0] = a; +} +// Doesn't compile here: +// b[1] = a + 1; + \end{minted} \onslide<2> - \highlightCppCode{3}{code_scopes} + \begin{minted}[linenos,highlightlines=3]{cpp} +int a = 1; +{ + int b[4]; + b[0] = a; +} +// Doesn't compile here: +// b[1] = a + 1; + \end{minted} \onslide<3> - \highlightCppCode{4}{code_scopes} + \begin{minted}[linenos,highlightlines=4]{cpp} +int a = 1; +{ + int b[4]; + b[0] = a; +} +// Doesn't compile here: +// b[1] = a + 1; + \end{minted} \onslide<4> - \highlightCppCode{7}{code_scopes} + \begin{minted}[linenos,highlightlines=7]{cpp} +int a = 1; +{ + int b[4]; + b[0] = a; +} +// Doesn't compile here: +// b[1] = a + 1; + \end{minted} \end{overprint} \columnbreak diff --git a/talk/setup.tex b/talk/setup.tex index a416f16b..2318b1a1 100644 --- a/talk/setup.tex +++ b/talk/setup.tex @@ -49,24 +49,8 @@ \usepackage{morewrites} \usepackage[utf8]{inputenc} \usepackage{newunicodechar} -\usepackage{scontents} -\makeatletter -\let\verbatimsc\@undefined -\let\endverbatimsc\@undefined -\makeatother \usepackage{minted} \newminted{tex}{linenos} -\newenvironment{verbatimsc} - {\VerbatimEnvironment - \begin{minted}[linenos,escapeinside=||]{cpp}} - {\end{minted}} -\newcommand\highlightCppCode[2]{ - \renewenvironment{verbatimsc} - {\VerbatimEnvironment - \begin{minted}[linenos,highlightlines={#1},escapeinside=||]{cpp}} - {\end{minted}} - \typestored{#2} -} \newminted{cpp}{gobble=4,linenos} \newminted{shell-session}{gobble=4} \newminted[makefile]{shell-session}{gobble=4}