\documentclass{beamer}
%
%
\makeatletter
\@ifundefined{lhs2tex.lhs2tex.sty.read}%
  {\@namedef{lhs2tex.lhs2tex.sty.read}{}%
   \newcommand\SkipToFmtEnd{}%
   \newcommand\EndFmtInput{}%
   \long\def\SkipToFmtEnd#1\EndFmtInput{}%
  }\SkipToFmtEnd

\newcommand\ReadOnlyOnce[1]{\@ifundefined{#1}{\@namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
  {<5><6><7><8>cmtex8
   <9>cmtex9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
  {<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<5><6><7><8>cmtt8
   <9>cmbtt9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
  {<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}}	% NEU

\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}

\EndFmtInput
\makeatother
%
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains,fit}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{multicol}

\usepackage{algorithm2e}
\usepackage{pgfkeys}


%% \newcommand{\SingleLinkedList}[1]{
%%   \foreach \datum/\anchor in {#1}
%%   \begin{scope}
%%     \node[rectangle, fill=yellow!30]{#2};
%%     \node[rectangle, below, fill=green!30](#1){$\cdot$};
%%   \end{scope}
%% }
%% \newcommand{\Null}{
%%   \node[circle, fill=black, minimum size=1em]{};
%% }
\pgfkeys {%
  /tikz/redbox/.style={%
    shape=rectangle,%
    minimum size=1.5em,%
    top color = white, %
    bottom color=red!50!black!50,
    inner sep=0pt,
    draw=black
  },
  /tikz/null/.style={%
    shape=circle,
    minimum size=0.5em,
    draw=black,
  },
  /tikz/greybox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black!20,
    inner sep=0pt,
    draw=black
  },
  /tikz/blackbox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black,
    inner sep=0pt,
    draw=black
   },
  /tikz/whitebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    fill=blue!40,
    draw=black
  },
  /tikz/whitetape/.style={
    shape=rectangle,
    minimum width=4em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluearr/.style={
    ->,
    line width=0.25em, 
    draw=blue!40
  },
  /tikz/greenarr/.style={
    ->,
    line width=0.25em, 
    draw=green!40!black!60
  }
}
    
\newcommand{\arraythree}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1, right=of a0#3](a1#3){#2};
    \node[#1, right=of a1#3](a1#3){#2};
  \end{tikzpicture}
}

\newcommand{\arraytwo}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1,right=of a0#3]{#2};
  \end{tikzpicture}
}
  
\newcommand{\Array}[0]{
  \arraythree{box}{}{a}{1}
}

\newcommand{\AArray}[0]{%
  \arraythree{bbox}{\Array}{b}{0.5}}
\newcommand{\AAArray}[0]{%
  \arraytwo{bbbox}{\AArray}{c}{0.25}}


\newcommand{\T}[1]{\ensuremath{T\left(#1\right)}}  
\newcommand{\BigOh}[1]{\ensuremath{O\left(#1\right)}}
\title{Fundamentals of Computing: Lecture 33}
\date{October 28, 2009}
\begin{document}
\begin{frame}
  \maketitle
\end{frame}

\begin{frame}
  \frametitle{Summary of last class}
  \begin{itemize}
    \pause
  \item C preprocession (\text{\tt cpp})
    \pause
  \item Including files 
    \pause
  \item Defining macros.
  \end{itemize}
\end{frame}

\begin{frame}
\frametitle{Including files}

\begin{tabbing}\tt
~\char35{}include~\char60{}stdio\char46{}h\char62{}\\
\tt ~\char35{}include~\char60{}openssl\char47{}x509\char46{}h\char62{}\\
\tt ~\char35{}include~\char34{}foo\char46{}h\char34{}~~
\end{tabbing}

\begin{itemize}
  \pause
\item The \text{\tt \char35{}include} line is replaced by the contents of the file
  \pause
\item The general syntax is 
  \pause
  \begin{tabbing}\tt
~~~~~\char35{}include~\char60{}filepath\char62{}~
\end{tabbing}
  \begin{tabbing}\tt
~~~~~\char35{}include~\char34{}filepath\char34{}
\end{tabbing}
  \pause
\item When angle backets are used the the file path is relative to a standard directory
  usually \text{\tt \char47{}usr\char47{}include\char47{}}.
  \pause
\item When double quotes the file path is relative ot the current director.

\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Macro definitions}

\pause
\begin{tabbing}\tt
~\char35{}define~ANSWER~42\\
\tt ~\char35{}define~ANSWERSTR~~\char34{}The~answer~is~42\char34{}\\
\tt ~\char35{}define~mul\char40{}a\char44{}b\char41{}~~\char40{}\char40{}a\char41{}~\char42{}~\char40{}b\char41{}\char41{}
\end{tabbing}
\pause

\begin{itemize}
  \pause
\item The macros are substituted literally.
  \pause
\item Happens before compilation
  \pause
\item Macros can take arguments
  \pause
\item Macro with arguments should be used with care.
\end{itemize}

\end{frame}

\begin{frame}
  \frametitle{The \text{\tt static} keyword}
  \begin{block}{Syntax of usage}
    static declaration
  \end{block}
  \begin{tabbing}\tt
~~~~~static~int~x\char59{}\\
\tt ~~~~~int~foo\char40{}\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~static~int~foo\char95{}invoke\char61{}0\char59{}\\
\tt ~~~~~~~foo\char95{}invoke~\char43{}\char43{}\char59{}\\
\tt ~~~~~~~return~foo\char95{}invoke\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
  \begin{itemize}
    \pause
  \item A variable can be declared static.
    \pause
  \item If the variable is a declared inside a function then all the invocation
    of the function uses the same variable.
    \pause
  \item If it is declared outside every function then it is visible
    only within that file.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{The keyword \text{\tt extern}}
  \frametitle{The \text{\tt extern} declaration}
  \begin{block}{Syntax}
    extern declaration;
  \end{block}

  \begin{itemize}
    \pause
    \item Says that the definition of the variable is somewhere else,
      possible in a different file.
      \pause
    \item Generally used only with variable declarations
      \pause
    \item With function declaration has no effect, default declaration
      is extern declaration.
      \pause
    \item A variable can be declared \text{\tt extern} many time but defined
      only once.
  \end{itemize}
\end{frame}

\end{document}


\begin{frame}
  \frametitle{Organising code into multiple files}
  \begin{itemize}
    \pause
  \item Leads to better organisation of source code.
    \pause
  \item Related parts can be grouped together
    \pause
  \item Seperate compilation and testing
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{An example library: 2D Geometry library}
  \begin{itemize}
  \item The header file \text{\tt geom2d\char46{}h} and a \text{\tt C} file \text{\tt geom2d\char46{}c} 
  \item The header file contains type definitions and function declarations
  \item THe \text{\tt C} files contains the definitions.
  \end{itemize}
\end{frame}
\begin{frame}
  \begin{itemize}
  \item The keyword \text{\tt extern}
  \item The keyword \text{\tt static}
  \item The \text{\tt \char35{}ifdef~\char35{}endif} trick to avoid multiple inclusion
  \end{itemize}
\end{frame}
