|
@@ -0,0 +1,615 @@
|
|
|
+\documentclass[10pt]{beamer}
|
|
|
+\setbeamercovered{transparent}
|
|
|
+\usetheme{Antibes}
|
|
|
+\usecolortheme{beaver}
|
|
|
+\usepackage[utf8]{inputenc}
|
|
|
+\usepackage[svgpath=images/]{svg}
|
|
|
+\usepackage{graphicx}
|
|
|
+\graphicspath{ {images/} }
|
|
|
+\usepackage[hyphenbreaks]{breakurl}
|
|
|
+\usepackage{hyperref}
|
|
|
+\hypersetup{breaklinks=true}
|
|
|
+\usepackage{subcaption}
|
|
|
+\usepackage{makecell}
|
|
|
+\usepackage{dirtytalk}
|
|
|
+\usepackage{amsmath}
|
|
|
+\usepackage{mathtools}
|
|
|
+\usepackage{listingsutf8}
|
|
|
+\usepackage[italian]{babel}
|
|
|
+
|
|
|
+% Todo red marker
|
|
|
+\usepackage{xcolor}
|
|
|
+\newcommand{\todo}[1]{}
|
|
|
+\renewcommand{\todo}[1]{{\color{red} TODO: {#1}}}
|
|
|
+
|
|
|
+% Stuff for presentation
|
|
|
+\usepackage{pgfpages}
|
|
|
+\setbeameroption{hide notes} % Only slides
|
|
|
+%\setbeameroption{show only notes} % Only notes
|
|
|
+%\setbeameroption{show notes}
|
|
|
+%\setbeameroption{show notes on second screen=right} % Both
|
|
|
+
|
|
|
+% Give a slight yellow tint to the notes page
|
|
|
+%\setbeamertemplate{note page}{\pagecolor{yellow!5}\insertnote}\usepackage{palatino}
|
|
|
+
|
|
|
+% Remove beamer navigation stuff
|
|
|
+%\setbeamertemplate{navigation symbols}{}
|
|
|
+
|
|
|
+\beamertemplatenavigationsymbolsempty
|
|
|
+
|
|
|
+%\setbeamerfont{page number in head/foot}{size=\small}
|
|
|
+%\setbeamertemplate{page number in head/foot}[framenumber]
|
|
|
+%\setbeamertemplate{page number in head/foot}[totalframenumber]
|
|
|
+\setbeamertemplate{footline}[frame number]
|
|
|
+
|
|
|
+% Listings packages
|
|
|
+\usepackage{verbatim}
|
|
|
+\usepackage{inconsolata}
|
|
|
+\usepackage{listings}
|
|
|
+\usepackage{multicol}
|
|
|
+\usepackage{lscape}
|
|
|
+\newcommand{\optcolor}[1]{\color{#1}}
|
|
|
+\lstset{
|
|
|
+ basicstyle={\ttfamily\footnotesize},
|
|
|
+ keywordstyle=\optcolor{blue},
|
|
|
+ stringstyle=\optcolor{red},
|
|
|
+ %commentstyle=\optcolor{green},
|
|
|
+ morecomment=[l][\optcolor{magenta}]{\#},
|
|
|
+ escapechar={|},
|
|
|
+}
|
|
|
+
|
|
|
+\definecolor{alt}{gray}{0.9}
|
|
|
+\definecolor{darkgreen}{rgb}{0,0.65,0}
|
|
|
+\lstdefinelanguage{llvm}{
|
|
|
+ basicstyle={\ttfamily\footnotesize},
|
|
|
+ morecomment = [l]{;},
|
|
|
+ commentstyle=\optcolor{darkgreen},
|
|
|
+ morestring=[b]",
|
|
|
+ sensitive = true,
|
|
|
+ classoffset=0,
|
|
|
+ alsoletter=:\%.,
|
|
|
+ keywordstyle=\optcolor{teal},
|
|
|
+ keywordsprefix={\%},
|
|
|
+ morekeywords={\@a},
|
|
|
+ %keywordstyle=\optcolor{darkgray},
|
|
|
+ classoffset=1,
|
|
|
+ keywordstyle=\optcolor{blue},
|
|
|
+ morekeywords={
|
|
|
+ define, declare, global, constant,
|
|
|
+ internal, external, private,
|
|
|
+ linkonce, linkonce_odr, weak, weak_odr, appending,
|
|
|
+ common, extern_weak,
|
|
|
+ thread_local, dllimport, dllexport,
|
|
|
+ hidden, protected, default,
|
|
|
+ except, deplibs,
|
|
|
+ volatile, fastcc, coldcc, cc, ccc,
|
|
|
+ x86_stdcallcc, x86_fastcallcc,
|
|
|
+ ptx_kernel, ptx_device,
|
|
|
+ signext, zeroext, inreg, sret, nounwind, noreturn,
|
|
|
+ nocapture, byval, nest, readnone, readonly, noalias, uwtable,
|
|
|
+ inlinehint, noinline, alwaysinline, optsize, ssp, sspreq,
|
|
|
+ noredzone, noimplicitfloat, naked, alignstack,
|
|
|
+ module, asm, align, tail, to,
|
|
|
+ addrspace, section, alias, sideeffect, c, gc,
|
|
|
+ target, datalayout, triple,
|
|
|
+ blockaddress
|
|
|
+ },
|
|
|
+ classoffset=2,keywordstyle=\optcolor{blue},
|
|
|
+ morekeywords={
|
|
|
+ fadd, sub, fsub, mul, fmul, add,
|
|
|
+ sdiv, udiv, fdiv, srem, urem, frem,
|
|
|
+ and, or, xor,
|
|
|
+ icmp, fcmp,
|
|
|
+ eq, ne, ugt, uge, ult, ule, sgt, sge, slt, sle,
|
|
|
+ oeq, ogt, oge, olt, ole, ord, ueq, ugt, uge,
|
|
|
+ ult, ule, une, uno,
|
|
|
+ nuw, nsw, exact, inbounds,
|
|
|
+ phi, call, select, shl, lshr, ashr, va_arg,
|
|
|
+ trunc, zext, sext,
|
|
|
+ fptrunc, fpext, fptoui, fptosi, uitofp, sitofp,
|
|
|
+ ptrtoint, inttoptr, bitcast,
|
|
|
+ ret, br, indirectbr, switch, invoke, unwind, unreachable,
|
|
|
+ malloc, alloca, free, load, store, getelementptr,
|
|
|
+ extractelement, insertelement, shufflevector,
|
|
|
+ extractvalue, insertvalue,
|
|
|
+ },
|
|
|
+ classoffset=3,
|
|
|
+ keywordstyle=\optcolor{purple},
|
|
|
+ morekeywords={
|
|
|
+ @v0, @a0, @t0, @ra, @pc, @r1, @ZF, @rax,@rsp
|
|
|
+ @main,@function,@root,@function_call
|
|
|
+ },
|
|
|
+ classoffset=4,keywordstyle=\optcolor{blue},
|
|
|
+ morekeywords={
|
|
|
+i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18,
|
|
|
+i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29, i30, i31, i32, i33, i34,
|
|
|
+i35, i36, i37, i38, i39, i40, i41, i42, i43, i44, i45, i46, i47, i48, i49, i50,
|
|
|
+i51, i52, i53, i54, i55, i56, i57, i58, i59, i60, i61, i62, i63, i64, i80, i512,
|
|
|
+void, half, float, double, fp128, x86_fp80, ppc_fp128, x86_mmx, label, metadata
|
|
|
+ },
|
|
|
+ classoffset=5,keywordstyle=\optcolor{teal},
|
|
|
+ morekeywords={
|
|
|
+ entry:,true:,epilogue:,bb.main:,bb._init.0x8,
|
|
|
+ dispatcher:,bb.one:,bb.two:,fallthrough:,call:,BB1:,BB2:,BB3:
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+% Packages for graphs
|
|
|
+\usepackage{tikz}
|
|
|
+\usetikzlibrary{arrows,automata}
|
|
|
+\usetikzlibrary{shapes.geometric}
|
|
|
+\usetikzlibrary{positioning}
|
|
|
+\usetikzlibrary{shapes.multipart}
|
|
|
+\usetikzlibrary{positioning}
|
|
|
+\usetikzlibrary{decorations.pathreplacing}
|
|
|
+\usetikzlibrary{fit}
|
|
|
+\usetikzlibrary{calc}
|
|
|
+\usetikzlibrary{matrix}
|
|
|
+\usetikzlibrary{patterns}
|
|
|
+\usetikzlibrary{quotes}
|
|
|
+\usetikzlibrary{shapes.misc}
|
|
|
+\tikzset{
|
|
|
+ diagonal fill/.style 2 args={fill=#2, path picture={
|
|
|
+ \fill[#1, sharp corners] (path picture bounding box.south west) -|
|
|
|
+ (path picture bounding box.north east) -- cycle;}},
|
|
|
+ reversed diagonal fill/.style 2 args={fill=#2, path picture={
|
|
|
+ \fill[#1, sharp corners] (path picture bounding box.north west) |-
|
|
|
+ (path picture bounding box.south east) -- cycle;}}
|
|
|
+ }
|
|
|
+\tikzset{
|
|
|
+ fadered/.style={
|
|
|
+ very thick,
|
|
|
+ draw=red!50!black!50,
|
|
|
+ top color=white,
|
|
|
+ rounded corners=.5mm,
|
|
|
+ bottom color=red!50!black!20, % and something else at the bottom
|
|
|
+ font=\sf,
|
|
|
+ text=black
|
|
|
+ },
|
|
|
+ faderedprime/.style={
|
|
|
+ very thick,
|
|
|
+ draw=blue!50!black!50,
|
|
|
+ top color=white,
|
|
|
+ rounded corners=.5mm,
|
|
|
+ bottom color=blue!50!black!20, % and something else at the bottom
|
|
|
+ font=\sf,
|
|
|
+ text=black
|
|
|
+ },
|
|
|
+ nonterminal/.style={
|
|
|
+ fadegray,
|
|
|
+ rectangle,
|
|
|
+ minimum size=6mm,
|
|
|
+ minimum width=20mm,
|
|
|
+ minimum height=7mm,
|
|
|
+ rounded corners=3mm
|
|
|
+ },
|
|
|
+ fadegray/.style={
|
|
|
+ text=black,
|
|
|
+ very thick,draw=black!50,
|
|
|
+ top color=white,
|
|
|
+ bottom color=black!20,
|
|
|
+ font=\sf
|
|
|
+ },
|
|
|
+ terminal/.style={
|
|
|
+ rectangle,
|
|
|
+ fadered,
|
|
|
+ minimum height=7mm,
|
|
|
+ minimum width=20mm,
|
|
|
+ rounded corners=3mm,
|
|
|
+ },
|
|
|
+ terminalprime/.style={
|
|
|
+ rectangle,
|
|
|
+ faderedprime,
|
|
|
+ minimum height=7mm,
|
|
|
+ minimum width=20mm,
|
|
|
+ rounded corners=3mm,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+% Visibility on slides
|
|
|
+%\usetikzlibrary{backgrounds}
|
|
|
+%\usetikzlibrary{arrows.meta,calc,shapes.callouts,shadows.blur,positioning}
|
|
|
+%% Conditional elements in TikZ drawings
|
|
|
+\tikzset{
|
|
|
+ invisible/.style={opacity=0,text opacity=0},
|
|
|
+ visible on/.style={alt=#1{}{invisible}},
|
|
|
+ alt/.code args={<#1>#2#3}{%
|
|
|
+ \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+\def\UrlBreaks{\do\/\do-}
|
|
|
+
|
|
|
+% Pgfplots imports
|
|
|
+\usepackage{pgfplots}
|
|
|
+\usepackage{pgfplotstable}
|
|
|
+\pgfplotsset{compat=1.13}
|
|
|
+
|
|
|
+% use acm colors
|
|
|
+\definecolor[named]{ACMBlue}{cmyk}{1,0.1,0,0.1}
|
|
|
+\definecolor[named]{ACMYellow}{cmyk}{0,0.16,1,0}
|
|
|
+\definecolor[named]{ACMOrange}{cmyk}{0,0.42,1,0.01}
|
|
|
+\definecolor[named]{ACMRed}{cmyk}{0,0.90,0.86,0}
|
|
|
+\definecolor[named]{ACMLightBlue}{cmyk}{0.49,0.01,0,0}
|
|
|
+\definecolor[named]{ACMGreen}{cmyk}{0.20,0,1,0.19}
|
|
|
+\definecolor[named]{ACMPurple}{cmyk}{0.55,1,0,0.15}
|
|
|
+\definecolor[named]{ACMDarkBlue}{cmyk}{1,0.58,0,0.21}
|
|
|
+
|
|
|
+% metropolis colors
|
|
|
+\definecolor{mDarkBrown}{HTML}{604c38}
|
|
|
+\definecolor{mDarkTeal}{HTML}{23373b}
|
|
|
+\definecolor{mLightBrown}{HTML}{EB811B}
|
|
|
+\definecolor{mLightGreen}{HTML}{14B03D}
|
|
|
+
|
|
|
+% Custom commands
|
|
|
+\newcommand{\ccode}[1]{\texttt{#1}}
|
|
|
+\usepackage{xspace}
|
|
|
+\newcommand{\newcommandx}[2]{\newcommand{#1}{#2\xspace}}
|
|
|
+\newcommandx{\revng}{\texttt{rev.ng}}
|
|
|
+\newcommandx{\llvm}{\textsc{llvm}}
|
|
|
+\newcommandx{\llvmcapi}{\textsc{llvm-c API}}
|
|
|
+\newcommandx{\llvmir}{\textsc{llvm ir}}
|
|
|
+\newcommandx{\qemuir}{\textsc{qemu ir}}
|
|
|
+\newcommandx{\qemu}{\textsc{qemu}}
|
|
|
+\newcommandx{\gcc}{\texttt{gcc}}
|
|
|
+\newcommand{\revamb}{\texttt{revamb}}
|
|
|
+\newcommand{\llvmcpy}{\texttt{llvmcpy}}
|
|
|
+
|
|
|
+\usepackage[noframe]{showframe}
|
|
|
+\usepackage{biblatex}[
|
|
|
+ backend=biber,
|
|
|
+ style=numeric,
|
|
|
+]
|
|
|
+
|
|
|
+% Python stuff
|
|
|
+% Default fixed font does not support bold face
|
|
|
+\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{10} % for bold
|
|
|
+\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{10} % for normal
|
|
|
+
|
|
|
+% Custom colors
|
|
|
+\usepackage{color}
|
|
|
+\definecolor{deepblue}{rgb}{0,0,0.5}
|
|
|
+\definecolor{deepred}{rgb}{0.6,0,0}
|
|
|
+\definecolor{deepgreen}{rgb}{0,0.5,0}
|
|
|
+
|
|
|
+\usepackage{listings}
|
|
|
+
|
|
|
+% Python style for highlighting
|
|
|
+\newcommand\pythonstyle{\lstset{
|
|
|
+ language=Python,
|
|
|
+ basicstyle=\ttm,
|
|
|
+ otherkeywords={self}, % Add keywords here
|
|
|
+ keywordstyle=\ttb\color{deepblue},
|
|
|
+ emph={MyClass,__init__}, % Custom highlighting
|
|
|
+ emphstyle=\ttb\color{deepred}, % Custom highlighting style
|
|
|
+ stringstyle=\color{deepgreen},
|
|
|
+ frame=tb, % Any extra options here
|
|
|
+ showstringspaces=false %
|
|
|
+}}
|
|
|
+
|
|
|
+% Python environment
|
|
|
+\lstnewenvironment{python}[1][]
|
|
|
+{
|
|
|
+ \pythonstyle
|
|
|
+ \lstset{#1}
|
|
|
+}
|
|
|
+{}
|
|
|
+
|
|
|
+% Python for external files
|
|
|
+\newcommand\pythonexternal[2][]{{
|
|
|
+ \pythonstyle
|
|
|
+\lstinputlisting[#1]{#2}}}
|
|
|
+\lstset{inputencoding=utf8/latin1}
|
|
|
+
|
|
|
+% Python for inline
|
|
|
+\newcommand\pythoninline[1]{{\pythonstyle\lstinline!#1!}}
|
|
|
+
|
|
|
+% C environment
|
|
|
+
|
|
|
+\definecolor{mGreen}{rgb}{0,0.6,0}
|
|
|
+\definecolor{mGray}{rgb}{0.5,0.5,0.5}
|
|
|
+\definecolor{mPurple}{rgb}{0.58,0,0.82}
|
|
|
+\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
|
|
|
+
|
|
|
+\lstdefinestyle{CStyle}{
|
|
|
+ backgroundcolor=\color{backgroundColour},
|
|
|
+ commentstyle=\color{mGreen},
|
|
|
+ keywordstyle=\color{magenta},
|
|
|
+ numberstyle=\tiny\color{mGray},
|
|
|
+ stringstyle=\color{mPurple},
|
|
|
+ basicstyle=\footnotesize,
|
|
|
+ breakatwhitespace=false,
|
|
|
+ breaklines=true,
|
|
|
+ captionpos=b,
|
|
|
+ keepspaces=true,
|
|
|
+ numbers=left,
|
|
|
+ numbersep=5pt,
|
|
|
+ showspaces=false,
|
|
|
+ showstringspaces=false,
|
|
|
+ showtabs=false,
|
|
|
+ tabsize=2,
|
|
|
+ language=C
|
|
|
+}
|
|
|
+\lstnewenvironment{C}[1][]
|
|
|
+{
|
|
|
+ \lstset{style=CStyle}
|
|
|
+}
|
|
|
+{}
|
|
|
+
|
|
|
+%\addbibresource{bibliography.bib}
|
|
|
+
|
|
|
+%\setbeamersize{text margin left=15pt,text margin right=15pt}
|
|
|
+
|
|
|
+% Information to be included in the title page:
|
|
|
+\title[]{Fondamenti di Informatica}
|
|
|
+%\subtitle{Presentation relative to ACACES 2019}
|
|
|
+\author{Andrea Gussoni\\andrea1.gussoni at polimi.it}
|
|
|
+\institute{Politecnico di Milano}
|
|
|
+\date{April 8, 2021}
|
|
|
+%\titlegraphic{\includegraphics[width=0.60\textwidth]{logo-polimi}}
|
|
|
+
|
|
|
+% Create section header slide
|
|
|
+\AtBeginSection{\frame{\sectionpage}}
|
|
|
+\begin{document}
|
|
|
+
|
|
|
+\frame{\titlepage
|
|
|
+ \note[item]{My name is ...}
|
|
|
+ \note[item]{Thank the audience.}}
|
|
|
+
|
|
|
+\begin{frame}
|
|
|
+ \frametitle{Table of Contents}
|
|
|
+ \tableofcontents
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\section{Ripasso Esercitazione Precedente}
|
|
|
+\begin{frame}{Ripasso}
|
|
|
+ \begin{alertblock}{}
|
|
|
+ Problemi con esercizi della precedente esercitazione?
|
|
|
+ \end{alertblock}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\section{Operatori Binari Bitwise}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Operatori Logici}
|
|
|
+ Ugualmente, esistono degli operatori logici binari:
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{A == B} Uguaglianza.
|
|
|
+ \item \ccode{A != B} Disuguaglianza.
|
|
|
+ \item \ccode{A >= B, A > B} Maggiore o uguale, Maggiore.
|
|
|
+ \item \ccode{A <= B, A < B} Minore o uguale, Minore.
|
|
|
+ \item \ccode{A \&\& B} and.
|
|
|
+ \item \ccode{A || B} or.
|
|
|
+ \end{itemize}
|
|
|
+
|
|
|
+ E anche un operatore logico unario:
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{!A} not.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Operatori bitwise}
|
|
|
+ Esistono anche gli operatori bitwise binari.
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{A \& B} and.
|
|
|
+ \item \ccode{A | B} or.
|
|
|
+ \item \ccode{A \char`\^ B} xor.
|
|
|
+ \item \ccode{A << B} Shift a sinistra.
|
|
|
+ \item \ccode{A >> B} Shift a destra.
|
|
|
+ \end{itemize}
|
|
|
+
|
|
|
+ E anche un operatore bitwise unario:
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{\char`\~A} not.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Operatori di assegnamento}
|
|
|
+ Conoscete già il principale operatore di assegnamento in C.
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{A = B} assegna ad A il valore di B.
|
|
|
+ \end{itemize}
|
|
|
+
|
|
|
+ Ma ci sono anche operatori che fanno una operazione ed un assegnamento, condesati in una notazione unica:
|
|
|
+ \begin{itemize}
|
|
|
+ \item \ccode{+=}, \ccode{-=}, \ccode{*=}, \ccode{/=}, \ccode{\%=}, \ccode{\&=}, \ccode{|=}, \ccode{\char`\^=}.
|
|
|
+ \end{itemize}
|
|
|
+
|
|
|
+ Ad esempio:
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ numero -= 42;
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+ è equivalente a:
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ numero = numero - 42;
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{comment}
|
|
|
+\begin{frame}[fragile]{Precedenza degli operatori}
|
|
|
+ Come abbiamo già accennato durante le esercitazioni riguardanti gli operatori logici, vi è una precedenza degli operatori da conoscere. In particolare, per quanto riguarda il C, bisogna rifarsi alla reference:
|
|
|
+ \begin{itemize}
|
|
|
+ \item \url{https://en.cppreference.com/w/c/language/operator_precedence}.
|
|
|
+ \item Sempre meglio però usare le parentesi, anche a costo di essere ridondanti.
|
|
|
+ \item Come side effect, noterete che l'uso delle parentesi migliora anche la leggibilità del codice altrui.
|
|
|
+ \item E soprattutto previene l'inserimento di bug accidentali dovuti a modifiche successive.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Costrutto di controllo while}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Il costrutto di controllo \ccode{while}, permette l'esecuzione del \emph{corpo} di esso fino a quando una condizione rimane vera (potenzialmente, infinitamente, come lo fareste?).
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ while (condizione) {
|
|
|
+ corpo_del_ciclo;
|
|
|
+ }
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+ \item Esempio:
|
|
|
+ \begin{C}
|
|
|
+ a = 10;
|
|
|
+ while (a > 5) {
|
|
|
+ b = b + c;
|
|
|
+ a = a - b;
|
|
|
+ }
|
|
|
+ c = c + 1;
|
|
|
+ \end{C}
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Costrutto di controllo do while}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Il costrutto di controllo \ccode{do while}, permette l'esecuzione del \emph{corpo} di esso fino a quando una condizione rimane vera, ma garantendo l'esecuzione di almeno la prima iterazione (la condizione è controllata \emph{dopo} il corpo del ciclo .
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ do {
|
|
|
+ corpo_del_ciclo;
|
|
|
+ } while (condizione);
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+ \item Esempio:
|
|
|
+ \begin{C}
|
|
|
+ a = 10;
|
|
|
+ do {
|
|
|
+ b = b + c;
|
|
|
+ a = a - b;
|
|
|
+ } while (a > 5)
|
|
|
+ c = c + 1;
|
|
|
+ \end{C}
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Costrutto di controllo for}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Il costrutto di controllo \ccode{for} serve per costruire un ciclo, ma con delle comode aggiunte per gestire il numero di iterazioni.
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ for (inizializzazione; condizione; incremento) {
|
|
|
+ corpo_ciclo;
|
|
|
+ }
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+ \item Esempio:
|
|
|
+ \begin{C}
|
|
|
+ a = 5;
|
|
|
+ for (i = 0; i < 10; i++) {
|
|
|
+ b = b + a;
|
|
|
+ }
|
|
|
+ b = b;
|
|
|
+ \end{C}
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{break e continue}
|
|
|
+ Sono inoltre disponibili due parole chiave che possono aiutare ulteriormente nella gestione delle iterazioni di un ciclo:
|
|
|
+ \begin{description}
|
|
|
+ \item [\ccode{break}]: interrompe immediatamente l'esecuzione del ciclo, ignorando la condizione e eventuali statement successivi del ciclo.
|
|
|
+ \item [\ccode{continue}]: passa alla successiva iterazione del ciclo, ignorando eventuali statement successivi nel corpo del ciclo. La condizione dell'iterazione successa viene comunque valutata, e in caso di ciclo \ccode{for} l'operazione di incremento viene comunque effettuata.
|
|
|
+ \end{description}
|
|
|
+\end{frame}
|
|
|
+\end{comment}
|
|
|
+
|
|
|
+\begin{comment}
|
|
|
+\begin{frame}[fragile]{Costrutto di controllo switch}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Il costrutto di controllo \ccode{switch} permette di eseguire differenti porzione di codice in base al valore di una variabile. Spesso può venire usato per ristrutturare catene di \ccode{if else if} in una composizione più elegante.
|
|
|
+ \begin{center}
|
|
|
+ \begin{C}
|
|
|
+ switch (variabile) {
|
|
|
+ case 1:
|
|
|
+ codice_1;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ codice_2;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ codice_default;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ \end{C}
|
|
|
+ \end{center}
|
|
|
+ \item la keyword \ccode{break} consente di non fare \emph{fallthrough}, che significa continuare con l'esecuzione del codice senza saltare alla fine dello scope dello \ccode{switch}.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Costrutto di controllo goto}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Non esiste nessun costrutto con nome \ccode{goto} in C.\
|
|
|
+ \pause
|
|
|
+ \item Jokes aside, lo statement \ccode{goto label}, può venire usato per reindirizzare l'esecuzione del codice ad una etichetta arbitraria posizionata nel codice. Si usa in specifici contesti, per quanto ci riguarda, bisogna assolutamente preferire e utilizzare codice strutturato (codice che contiene \ccode{goto} è anche chiamato codice non strutturato).
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+\end{comment}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Operatori Bitwise}
|
|
|
+ \begin{center}
|
|
|
+ \Huge{Esempi pratici}
|
|
|
+ \end{center}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\section{Esercizi}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Tabelline}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Implementare un programma in linguaggio C che stampa, fornendo in output una formattazione ragionevole, le tabelline dei numeri dall'1 al 9. Si richiede, in particolare, di stampare l'output andando a capo alla fine della tabellina di ogni numero, e di allineare verticalmente le varie linee delle tabelline.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Numeri Triangolari}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Implementare un programma in linguaggio C che, letto un intero da user input, stabilisce se il numero è un numero triangolare.
|
|
|
+
|
|
|
+ \item Osservazione: Viene definito numero triangolare, un numero costituito dalla somma dei primi interi positivi N, per un certo N.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Sequenze Pari}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Implementare un programma in linguaggio C che legge una sequenza (di lunghezza arbitraria) di interi positivi terminata dal valore 0, e al termine della sequenza, stampa quante terne di numeri consecutivi diversi tra loro e pari sono contenute nella sequenza.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{frame}[fragile]{Numeri Affiatati}
|
|
|
+ \begin{itemize}
|
|
|
+ \item Implementare un programma in linguaggio C che:
|
|
|
+ \begin{itemize}
|
|
|
+ \item elenca tutte le coppie di numeri affiatati, diversi tra loro, composti di due cifre.
|
|
|
+ \item come sopra, ma dove il numero maggiore della coppia deve anche essere primo.
|
|
|
+ \item elenca i numeri autoaffiati (ovvero affiatati con se stessi).
|
|
|
+ \end{itemize}
|
|
|
+
|
|
|
+ \item Osservazione: Due numeri si dicono affiatati, se la loro somma è uguale al prodotto delle cifre che li compongono.
|
|
|
+ \end{itemize}
|
|
|
+\end{frame}
|
|
|
+
|
|
|
+\begin{comment}
|
|
|
+\section{Extra}
|
|
|
+\begin{frame}[fragile]{Monte Carlo}
|
|
|
+ Scrivere un programma che calcoli il valore di $\pi$, utilizzando il metodo di Monte Carlo.
|
|
|
+\end{frame}
|
|
|
+\end{comment}
|
|
|
+
|
|
|
+\begin{comment}
|
|
|
+\begin{frame}[t,allowframebreaks]
|
|
|
+ \frametitle{References}
|
|
|
+ \nocite{*}
|
|
|
+ \printbibliography
|
|
|
+\end{frame}
|
|
|
+\end{comment}
|
|
|
+
|
|
|
+\begin{comment}
|
|
|
+\begin{frame}
|
|
|
+ \frametitle{License}
|
|
|
+ \begin{center}
|
|
|
+ \vfill
|
|
|
+ \includesvg[height=1.5cm]{by-sa}\\
|
|
|
+ {\footnotesize These slides are published under a Creative Commons Attribution-ShareAlike 4.0 license\footnote{\url{https://creativecommons.org/licenses/by-sa/4.0/}}.}
|
|
|
+ \end{center}
|
|
|
+\end{frame}
|
|
|
+\end{comment}
|
|
|
+
|
|
|
+\end{document}
|