From 82547a200902247a65a4fdb9a30602a052d2137d Mon Sep 17 00:00:00 2001 From: Orestis <orestis.malaspinas@pm.me> Date: Tue, 15 Oct 2024 13:05:29 +0200 Subject: [PATCH] 2024 --- slides/figs/pointer_struct.svg | 454 +++++++++++++++++++++++++++++++++ slides/structs.md | 191 ++++++++++++++ 2 files changed, 645 insertions(+) create mode 100644 slides/figs/pointer_struct.svg create mode 100644 slides/structs.md diff --git a/slides/figs/pointer_struct.svg b/slides/figs/pointer_struct.svg new file mode 100644 index 0000000..d7b41ce --- /dev/null +++ b/slides/figs/pointer_struct.svg @@ -0,0 +1,454 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + width="169.70569mm" + height="96.099983mm" + viewBox="0 0 169.70569 96.099986" + version="1.1" + id="svg8" + inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)" + sodipodi:docname="pointer_struct.svg" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns="http://www.w3.org/2000/svg" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:ns1="http://www.iki.fi/pav/software/textext/"> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="0.9899495" + inkscape:cx="169.70563" + inkscape:cy="110.6117" + inkscape:document-units="mm" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="944" + inkscape:window-height="1022" + inkscape:window-x="962" + inkscape:window-y="44" + inkscape:window-maximized="1" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" + inkscape:pagecheckerboard="0"> + <inkscape:grid + id="grid819" + type="xygrid" + originx="22.40475" + originy="-104.72045" /> + </sodipodi:namedview> + <defs + id="defs2"> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="marker3314" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path3312" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="marker3284" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path3028" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lstart" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lstart" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path3025" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(1.1,0,0,1.1,1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend" + style="overflow:visible" + inkscape:isstock="true"> + <path + id="path8951" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" + inkscape:connector-curvature="0" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-7" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path8951-5" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-9" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path8951-8" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-7-2" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path8951-5-8" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + <marker + inkscape:stockid="Arrow2Lend" + orient="auto" + refY="0" + refX="0" + id="Arrow2Lend-1" + style="overflow:visible" + inkscape:isstock="true"> + <path + inkscape:connector-curvature="0" + id="path8951-3" + style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1" + d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z" + transform="matrix(-1.1,0,0,-1.1,-1.1,0)" /> + </marker> + </defs> + <metadata + id="metadata5"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + transform="translate(22.404752,-95.547514)"> + <g + transform="matrix(0.48784069,0,0,1,-19.844943,-20.032731)" + id="g846-7-2" + style="fill:none;stroke:#0000ff;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1"> + <rect + y="156.77083" + x="99.218758" + height="9.260417" + width="29.104166" + id="rect821-3-5-2" + style="opacity:1;fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + y="156.77083" + x="128.32292" + height="9.260417" + width="29.104166" + id="rect821-6-3-8" + style="opacity:1;fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1" /> + </g> + <rect + style="opacity:1;fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:0.5, 1.5;stroke-dashoffset:0;stroke-opacity:1" + id="rect821-3-6-7" + width="14.198196" + height="9.260417" + x="0.16160744" + y="136.7381" /> + <rect + style="opacity:1;fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:0.5, 1.5;stroke-dashoffset:0;stroke-opacity:1" + id="rect821-6-2-3" + width="14.198196" + height="9.260417" + x="14.359803" + y="136.7381" /> + <g + id="g1424" + transform="translate(-49.091184)"> + <g + transform="matrix(0.4878407,0,0,1,85.797382,-20.032732)" + id="g846-7-2-6" + style="fill:none;stroke:#ff0007;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1"> + <rect + y="156.77083" + x="99.218758" + height="9.260417" + width="29.104166" + id="rect821-3-5-2-7" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ff0007;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1" /> + <rect + y="156.77083" + x="128.32292" + height="9.260417" + width="29.104166" + id="rect821-6-3-8-5" + style="opacity:1;fill:none;fill-opacity:1;stroke:#ff0007;stroke-width:0.715865;stroke-miterlimit:4;stroke-dasharray:0.715865, 2.14759;stroke-dashoffset:0;stroke-opacity:1" /> + </g> + <rect + style="opacity:1;fill:none;fill-opacity:1;stroke:#ff0007;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:0.5, 1.5;stroke-dashoffset:0;stroke-opacity:1" + id="rect821-3-6-7-3" + width="14.198196" + height="9.260417" + x="105.80393" + y="136.7381" /> + <rect + style="opacity:1;fill:none;fill-opacity:1;stroke:#ff0007;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:0.5, 1.5;stroke-dashoffset:0;stroke-opacity:1" + id="rect821-6-2-3-5" + width="14.198196" + height="9.260417" + x="120.00212" + y="136.7381" /> + </g> + <path + style="fill:none;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker3284)" + d="M -1.3502974,187.19792 C -11.771154,175.55249 -19.079084,167.53113 0.16160744,145.99852" + id="path2993" + inkscape:connector-curvature="0" + sodipodi:nodetypes="cc" /> + <ellipse + style="fill:none;fill-opacity:1;stroke:#ff0007;stroke-width:0.404612;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + id="path3710" + cx="62.44809" + cy="138.51381" + rx="84.650536" + ry="32.742634" /> + <g + id="g4075" + ns1:jacobian_sqrt="1.0" + inkscapeversion="0.92.3" + ns1:alignment="middle center" + ns1:scale="2.83464566935" + ns1:preamble="/home/malaspor/.config/inkscape/extensions/textext/default_packages.tex" + ns1:text="pas encore allou\\\'ee" + ns1:pdfconverter="pdf2svg" + ns1:texconverter="pdflatex" + ns1:version="0.9.0" + transform="translate(-128.64259,-32.264361)"> + <g + id="g4073"> + <g + id="g4035" + style="fill:#000000;fill-opacity:1"> + <path + id="path4029" + transform="translate(148.712,134.765)" + d="m 1.71875,-3.75 v -0.65625 l -1.4375,0.109375 v 0.3125 c 0.703125,0 0.78125,0.0625 0.78125,0.5 v 4.65625 C 1.0625,1.625 0.953125,1.625 0.28125,1.625 V 1.9375 C 0.625,1.921875 1.140625,1.90625 1.390625,1.90625 c 0.28125,0 0.78125,0.015625 1.125,0.03125 V 1.625 C 1.859375,1.625 1.75,1.625 1.75,1.171875 V -0.59375 c 0.046875,0.171875 0.46875,0.703125 1.21875,0.703125 1.1875,0 2.21875,-0.984375 2.21875,-2.265625 0,-1.265625 -0.953125,-2.25 -2.078125,-2.25 -0.78125,0 -1.203125,0.4375 -1.390625,0.65625 z M 1.75,-1.140625 v -2.21875 C 2.03125,-3.875 2.515625,-4.15625 3.03125,-4.15625 c 0.734375,0 1.328125,0.875 1.328125,2 0,1.203125 -0.6875,2.046875 -1.421875,2.046875 -0.40625,0 -0.78125,-0.203125 -1.046875,-0.609375 C 1.75,-0.921875 1.75,-0.9375 1.75,-1.140625 Z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4031" + transform="translate(154.24722,134.765)" + d="m 3.3125,-0.75 c 0.046875,0.390625 0.3125,0.8125 0.78125,0.8125 0.21875,0 0.828125,-0.140625 0.828125,-0.953125 v -0.5625 h -0.25 v 0.5625 c 0,0.578125 -0.25,0.640625 -0.359375,0.640625 -0.328125,0 -0.375,-0.453125 -0.375,-0.5 v -1.984375 c 0,-0.421875 0,-0.8125 -0.359375,-1.1875 C 3.1875,-4.3125 2.6875,-4.46875 2.21875,-4.46875 c -0.828125,0 -1.515625,0.46875 -1.515625,1.125 0,0.296875 0.203125,0.46875 0.46875,0.46875 0.28125,0 0.453125,-0.203125 0.453125,-0.453125 0,-0.125 -0.046875,-0.453125 -0.515625,-0.453125 C 1.390625,-4.140625 1.875,-4.25 2.1875,-4.25 c 0.5,0 1.0625,0.390625 1.0625,1.28125 v 0.359375 c -0.515625,0.03125 -1.203125,0.0625 -1.828125,0.359375 -0.75,0.34375 -1,0.859375 -1,1.296875 0,0.8125 0.96875,1.0625 1.59375,1.0625 0.65625,0 1.109375,-0.40625 1.296875,-0.859375 z M 3.25,-2.390625 v 1 c 0,0.9375 -0.71875,1.28125 -1.171875,1.28125 -0.484375,0 -0.890625,-0.34375 -0.890625,-0.84375 0,-0.546875 0.421875,-1.375 2.0625,-1.4375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4033" + transform="translate(159.22852,134.765)" + d="m 2.078125,-1.9375 c 0.21875,0.046875 1.03125,0.203125 1.03125,0.921875 0,0.5 -0.34375,0.90625 -1.125,0.90625 -0.84375,0 -1.203125,-0.5625 -1.390625,-1.421875 C 0.5625,-1.65625 0.5625,-1.6875 0.453125,-1.6875 c -0.125,0 -0.125,0.0625 -0.125,0.234375 V -0.125 c 0,0.171875 0,0.234375 0.109375,0.234375 0.046875,0 0.0625,-0.015625 0.25,-0.203125 0.015625,-0.015625 0.015625,-0.03125 0.203125,-0.21875 0.4375,0.40625 0.890625,0.421875 1.09375,0.421875 1.140625,0 1.609375,-0.671875 1.609375,-1.390625 0,-0.515625 -0.296875,-0.828125 -0.421875,-0.9375 C 2.84375,-2.546875 2.453125,-2.625 2.03125,-2.703125 1.46875,-2.8125 0.8125,-2.9375 0.8125,-3.515625 c 0,-0.359375 0.25,-0.765625 1.109375,-0.765625 1.09375,0 1.15625,0.90625 1.171875,1.203125 0,0.09375 0.09375,0.09375 0.109375,0.09375 0.140625,0 0.140625,-0.046875 0.140625,-0.234375 v -1.015625 c 0,-0.15625 0,-0.234375 -0.109375,-0.234375 -0.046875,0 -0.078125,0 -0.203125,0.125 -0.03125,0.03125 -0.125,0.125 -0.171875,0.15625 -0.375,-0.28125 -0.78125,-0.28125 -0.9375,-0.28125 -1.21875,0 -1.59375,0.671875 -1.59375,1.234375 0,0.34375 0.15625,0.625 0.421875,0.84375 0.328125,0.25 0.609375,0.3125 1.328125,0.453125 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + </g> + <g + id="g4049" + style="fill:#000000;fill-opacity:1"> + <path + id="path4037" + transform="translate(166.47532,134.765)" + d="M 1.109375,-2.515625 C 1.171875,-4 2.015625,-4.25 2.359375,-4.25 c 1.015625,0 1.125,1.34375 1.125,1.734375 z m 0,0.21875 h 2.78125 c 0.21875,0 0.25,0 0.25,-0.21875 0,-0.984375 -0.546875,-1.953125 -1.78125,-1.953125 -1.15625,0 -2.078125,1.03125 -2.078125,2.28125 0,1.328125 1.046875,2.296875 2.1875,2.296875 C 3.6875,0.109375 4.140625,-1 4.140625,-1.1875 4.140625,-1.28125 4.0625,-1.3125 4,-1.3125 c -0.078125,0 -0.109375,0.0625 -0.125,0.140625 -0.34375,1.03125 -1.25,1.03125 -1.34375,1.03125 -0.5,0 -0.890625,-0.296875 -1.125,-0.671875 -0.296875,-0.46875 -0.296875,-1.125 -0.296875,-1.484375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4039" + transform="translate(170.90269,134.765)" + d="M 1.09375,-3.421875 V -0.75 c 0,0.4375 -0.109375,0.4375 -0.78125,0.4375 V 0 c 0.359375,-0.015625 0.859375,-0.03125 1.140625,-0.03125 0.25,0 0.765625,0.015625 1.109375,0.03125 v -0.3125 c -0.671875,0 -0.78125,0 -0.78125,-0.4375 V -2.59375 C 1.78125,-3.625 2.5,-4.1875 3.125,-4.1875 c 0.640625,0 0.75,0.53125 0.75,1.109375 V -0.75 c 0,0.4375 -0.109375,0.4375 -0.78125,0.4375 V 0 c 0.34375,-0.015625 0.859375,-0.03125 1.125,-0.03125 0.25,0 0.78125,0.015625 1.109375,0.03125 v -0.3125 c -0.515625,0 -0.765625,0 -0.765625,-0.296875 v -1.90625 c 0,-0.859375 0,-1.15625 -0.3125,-1.515625 -0.140625,-0.171875 -0.46875,-0.375 -1.046875,-0.375 C 2.46875,-4.40625 2,-3.984375 1.71875,-3.359375 V -4.40625 L 0.3125,-4.296875 v 0.3125 c 0.703125,0 0.78125,0.0625 0.78125,0.5625 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4041" + transform="translate(176.43792,134.765)" + d="m 1.171875,-2.171875 c 0,-1.625 0.8125,-2.046875 1.34375,-2.046875 0.09375,0 0.71875,0.015625 1.0625,0.375 -0.40625,0.03125 -0.46875,0.328125 -0.46875,0.453125 0,0.265625 0.1875,0.453125 0.453125,0.453125 0.265625,0 0.46875,-0.15625 0.46875,-0.46875 0,-0.671875 -0.765625,-1.0625 -1.53125,-1.0625 -1.25,0 -2.15625,1.078125 -2.15625,2.3125 0,1.28125 0.984375,2.265625 2.140625,2.265625 1.328125,0 1.65625,-1.203125 1.65625,-1.296875 0,-0.09375 -0.109375,-0.09375 -0.140625,-0.09375 -0.078125,0 -0.109375,0.03125 -0.125,0.09375 -0.28125,0.921875 -0.9375,1.046875 -1.296875,1.046875 -0.53125,0 -1.40625,-0.421875 -1.40625,-2.03125 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4043" + transform="translate(180.86529,134.765)" + d="M 4.6875,-2.140625 C 4.6875,-3.40625 3.703125,-4.46875 2.5,-4.46875 c -1.25,0 -2.21875,1.09375 -2.21875,2.328125 0,1.296875 1.03125,2.25 2.203125,2.25 1.203125,0 2.203125,-0.984375 2.203125,-2.25 z m -2.1875,2 c -0.4375,0 -0.875,-0.203125 -1.140625,-0.671875 -0.25,-0.4375 -0.25,-1.046875 -0.25,-1.40625 0,-0.390625 0,-0.921875 0.234375,-1.359375 C 1.609375,-4.03125 2.078125,-4.25 2.484375,-4.25 c 0.4375,0 0.859375,0.21875 1.125,0.65625 0.265625,0.421875 0.265625,1 0.265625,1.375 0,0.359375 0,0.90625 -0.21875,1.34375 C 3.421875,-0.421875 2.984375,-0.140625 2.5,-0.140625 Z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4045" + transform="translate(185.84659,134.765)" + d="M 1.671875,-3.3125 V -4.40625 L 0.28125,-4.296875 v 0.3125 c 0.703125,0 0.78125,0.0625 0.78125,0.5625 V -0.75 c 0,0.4375 -0.109375,0.4375 -0.78125,0.4375 V 0 c 0.390625,-0.015625 0.859375,-0.03125 1.140625,-0.03125 0.390625,0 0.859375,0 1.265625,0.03125 V -0.3125 H 2.46875 c -0.734375,0 -0.75,-0.109375 -0.75,-0.46875 V -2.3125 c 0,-0.984375 0.421875,-1.875 1.171875,-1.875 0.0625,0 0.09375,0 0.109375,0.015625 -0.03125,0 -0.234375,0.125 -0.234375,0.390625 0,0.265625 0.21875,0.421875 0.4375,0.421875 0.171875,0 0.421875,-0.125 0.421875,-0.4375 0,-0.3125 -0.3125,-0.609375 -0.734375,-0.609375 -0.734375,0 -1.09375,0.671875 -1.21875,1.09375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4047" + transform="translate(189.74895,134.765)" + d="M 1.109375,-2.515625 C 1.171875,-4 2.015625,-4.25 2.359375,-4.25 c 1.015625,0 1.125,1.34375 1.125,1.734375 z m 0,0.21875 h 2.78125 c 0.21875,0 0.25,0 0.25,-0.21875 0,-0.984375 -0.546875,-1.953125 -1.78125,-1.953125 -1.15625,0 -2.078125,1.03125 -2.078125,2.28125 0,1.328125 1.046875,2.296875 2.1875,2.296875 C 3.6875,0.109375 4.140625,-1 4.140625,-1.1875 4.140625,-1.28125 4.0625,-1.3125 4,-1.3125 c -0.078125,0 -0.109375,0.0625 -0.125,0.140625 -0.34375,1.03125 -1.25,1.03125 -1.34375,1.03125 -0.5,0 -0.890625,-0.296875 -1.125,-0.671875 -0.296875,-0.46875 -0.296875,-1.125 -0.296875,-1.484375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + </g> + <g + id="g4061" + style="fill:#000000;fill-opacity:1"> + <path + id="path4051" + transform="translate(197.50383,134.765)" + d="m 3.3125,-0.75 c 0.046875,0.390625 0.3125,0.8125 0.78125,0.8125 0.21875,0 0.828125,-0.140625 0.828125,-0.953125 v -0.5625 h -0.25 v 0.5625 c 0,0.578125 -0.25,0.640625 -0.359375,0.640625 -0.328125,0 -0.375,-0.453125 -0.375,-0.5 v -1.984375 c 0,-0.421875 0,-0.8125 -0.359375,-1.1875 C 3.1875,-4.3125 2.6875,-4.46875 2.21875,-4.46875 c -0.828125,0 -1.515625,0.46875 -1.515625,1.125 0,0.296875 0.203125,0.46875 0.46875,0.46875 0.28125,0 0.453125,-0.203125 0.453125,-0.453125 0,-0.125 -0.046875,-0.453125 -0.515625,-0.453125 C 1.390625,-4.140625 1.875,-4.25 2.1875,-4.25 c 0.5,0 1.0625,0.390625 1.0625,1.28125 v 0.359375 c -0.515625,0.03125 -1.203125,0.0625 -1.828125,0.359375 -0.75,0.34375 -1,0.859375 -1,1.296875 0,0.8125 0.96875,1.0625 1.59375,1.0625 0.65625,0 1.109375,-0.40625 1.296875,-0.859375 z M 3.25,-2.390625 v 1 c 0,0.9375 -0.71875,1.28125 -1.171875,1.28125 -0.484375,0 -0.890625,-0.34375 -0.890625,-0.84375 0,-0.546875 0.421875,-1.375 2.0625,-1.4375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4053" + transform="translate(202.48513,134.765)" + d="M 1.765625,-6.921875 0.328125,-6.8125 V -6.5 c 0.703125,0 0.78125,0.0625 0.78125,0.5625 V -0.75 c 0,0.4375 -0.109375,0.4375 -0.78125,0.4375 V 0 C 0.65625,-0.015625 1.1875,-0.03125 1.4375,-0.03125 c 0.25,0 0.734375,0.015625 1.109375,0.03125 v -0.3125 c -0.671875,0 -0.78125,0 -0.78125,-0.4375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4055" + transform="translate(205.25274,134.765)" + d="M 1.765625,-6.921875 0.328125,-6.8125 V -6.5 c 0.703125,0 0.78125,0.0625 0.78125,0.5625 V -0.75 c 0,0.4375 -0.109375,0.4375 -0.78125,0.4375 V 0 C 0.65625,-0.015625 1.1875,-0.03125 1.4375,-0.03125 c 0.25,0 0.734375,0.015625 1.109375,0.03125 v -0.3125 c -0.671875,0 -0.78125,0 -0.78125,-0.4375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4057" + transform="translate(208.02035,134.765)" + d="M 4.6875,-2.140625 C 4.6875,-3.40625 3.703125,-4.46875 2.5,-4.46875 c -1.25,0 -2.21875,1.09375 -2.21875,2.328125 0,1.296875 1.03125,2.25 2.203125,2.25 1.203125,0 2.203125,-0.984375 2.203125,-2.25 z m -2.1875,2 c -0.4375,0 -0.875,-0.203125 -1.140625,-0.671875 -0.25,-0.4375 -0.25,-1.046875 -0.25,-1.40625 0,-0.390625 0,-0.921875 0.234375,-1.359375 C 1.609375,-4.03125 2.078125,-4.25 2.484375,-4.25 c 0.4375,0 0.859375,0.21875 1.125,0.65625 0.265625,0.421875 0.265625,1 0.265625,1.375 0,0.359375 0,0.90625 -0.21875,1.34375 C 3.421875,-0.421875 2.984375,-0.140625 2.5,-0.140625 Z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4059" + transform="translate(213.00165,134.765)" + d="M 3.890625,-0.78125 V 0.109375 L 5.328125,0 V -0.3125 C 4.640625,-0.3125 4.5625,-0.375 4.5625,-0.875 v -3.53125 l -1.46875,0.109375 v 0.3125 c 0.6875,0 0.78125,0.0625 0.78125,0.5625 v 1.765625 c 0,0.875 -0.484375,1.546875 -1.21875,1.546875 -0.828125,0 -0.875,-0.46875 -0.875,-0.984375 v -3.3125 L 0.3125,-4.296875 v 0.3125 c 0.78125,0 0.78125,0.03125 0.78125,0.90625 v 1.5 c 0,0.78125 0,1.6875 1.515625,1.6875 0.5625,0 1,-0.28125 1.28125,-0.890625 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + </g> + <g + id="g4065" + style="fill:#000000;fill-opacity:1"> + <path + id="path4063" + transform="translate(218.25792,134.765)" + d="M 3.734375,-6.296875 C 3.828125,-6.375 3.90625,-6.484375 3.90625,-6.59375 c 0,-0.1875 -0.171875,-0.359375 -0.359375,-0.359375 -0.140625,0 -0.25,0.109375 -0.296875,0.171875 l -1.203125,1.515625 0.171875,0.1875 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + </g> + <g + id="g4071" + style="fill:#000000;fill-opacity:1"> + <path + id="path4067" + transform="translate(218.53687,134.765)" + d="M 1.109375,-2.515625 C 1.171875,-4 2.015625,-4.25 2.359375,-4.25 c 1.015625,0 1.125,1.34375 1.125,1.734375 z m 0,0.21875 h 2.78125 c 0.21875,0 0.25,0 0.25,-0.21875 0,-0.984375 -0.546875,-1.953125 -1.78125,-1.953125 -1.15625,0 -2.078125,1.03125 -2.078125,2.28125 0,1.328125 1.046875,2.296875 2.1875,2.296875 C 3.6875,0.109375 4.140625,-1 4.140625,-1.1875 4.140625,-1.28125 4.0625,-1.3125 4,-1.3125 c -0.078125,0 -0.109375,0.0625 -0.125,0.140625 -0.34375,1.03125 -1.25,1.03125 -1.34375,1.03125 -0.5,0 -0.890625,-0.296875 -1.125,-0.671875 -0.296875,-0.46875 -0.296875,-1.125 -0.296875,-1.484375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + <path + id="path4069" + transform="translate(222.96425,134.765)" + d="M 1.109375,-2.515625 C 1.171875,-4 2.015625,-4.25 2.359375,-4.25 c 1.015625,0 1.125,1.34375 1.125,1.734375 z m 0,0.21875 h 2.78125 c 0.21875,0 0.25,0 0.25,-0.21875 0,-0.984375 -0.546875,-1.953125 -1.78125,-1.953125 -1.15625,0 -2.078125,1.03125 -2.078125,2.28125 0,1.328125 1.046875,2.296875 2.1875,2.296875 C 3.6875,0.109375 4.140625,-1 4.140625,-1.1875 4.140625,-1.28125 4.0625,-1.3125 4,-1.3125 c -0.078125,0 -0.109375,0.0625 -0.125,0.140625 -0.34375,1.03125 -1.25,1.03125 -1.34375,1.03125 -0.5,0 -0.890625,-0.296875 -1.125,-0.671875 -0.296875,-0.46875 -0.296875,-1.125 -0.296875,-1.484375 z m 0,0" + style="stroke:none;stroke-width:0" + inkscape:connector-curvature="0" /> + </g> + </g> + </g> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:8.4167px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.210418" + x="-3.3584552" + y="132.0246" + id="text5410"><tspan + sodipodi:role="line" + id="tspan5408" + style="stroke-width:0.210418" + x="-3.3584552" + y="132.0246">fraction_t</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:8.4167px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.210418" + x="1.8167764" + y="153.79558" + id="text5410-7"><tspan + sodipodi:role="line" + id="tspan5408-5" + style="stroke-width:0.210418" + x="1.8167764" + y="153.79558">num</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:8.4167px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.210418" + x="59.858959" + y="154.63602" + id="text5410-35"><tspan + sodipodi:role="line" + id="tspan5408-62" + style="stroke-width:0.210418" + x="59.858959" + y="154.63602">denom</tspan></text> + <text + xml:space="preserve" + style="font-style:normal;font-weight:normal;font-size:8.4167px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.210418" + x="0.63656694" + y="189.66251" + id="text5410-3"><tspan + sodipodi:role="line" + id="tspan5408-6" + style="stroke-width:0.210418" + x="0.63656694" + y="189.66251">fraction_t *frac;</tspan></text> + </g> +</svg> diff --git a/slides/structs.md b/slides/structs.md new file mode 100644 index 0000000..114765d --- /dev/null +++ b/slides/structs.md @@ -0,0 +1,191 @@ +--- +title: "Structures" +date: "2024-10-15" +--- + +# Les fractions + +* Représentation d'un nombre sous la forme de la division de deux entiers +\begin{equation*} +q=\frac{n}{d}, +\end{equation*} +avec $q\in\mathds{Q}$, $n\in\mathds{Z}$ le numérateur et $d\in\mathds{Z}^+$ le dénominateur (**attention** $d\neq 0$). +* Ces nombres peuvent s'additionner +\begin{align*} +&q_1=\frac{n_1}{d_1},\quad q_2=\frac{n_2}{d_2},\\ +&q_3=q_1+q_2=\frac{n_1d_2+n_2d_1}{d_1d_2}. +\end{align*} +se soustraire, multiplier, diviser. + +# Représentation informatique + +## Fractions + +* Numérateur: `int32_t num`; +* Dénominateur: `int32_t denom`. + +## Addition + +```C +int32_t num1 = 1, denom1 = 2; +int32_t num2 = 1, denom2 = 3; +int32_t num3 = num1 * denom2 + num2 * denom1; +int32_t denom3 = denom1 * denom2; +``` + +## Pas super pratique.... + +# Types composés: `struct`{.C} (1/5) + +## On peut faire mieux + +* Plusieurs variables qu'on aimerait regrouper dans un seul type: `struct`{.C}. + +```C +struct fraction { // déclaration du type + int32_t num, denom; +}; + +struct fraction frac; // déclaration de frac +// c'est un type tout comme int, float, bool, etc. +``` + +# Types composés: `struct`{.C} (2/5) + +\footnotesize + +## Simplifications + +- `typedef`{.C} permet de définir un nouveau type. + + ```C + typedef unsigned int uint; + typedef struct fraction fraction_t; + typedef struct fraction { + int32_t num, denom; + } fraction_t; + ``` +- L'initialisation peut aussi se faire avec + + ```C + fraction_t frac = {1, -2}; // num = 1, denom = -2 + fraction_t frac = {.denom = 1, .num = -2}; // idem + fraction_t frac = {.denom = 1}; // argl! .num non initialisé + fraction_t frac2 = frac; // copie + ``` + +# Types composés: `struct`{.C} (3/5) + +\footnotesize + +## Pointeurs + +- Comme pour tout type, on peut avoir des pointeurs vers un `struct`{.C}. +- Les champs sont accessible avec le sélecteur `->`{.C} + + ```C + fraction_t *frac; // on crée un pointeur + frac->num = 1; // seg fault... + frac->denom = -1; // mémoire pas allouée. + ``` + +{width=50%} + +# Types composés: `struct`{.C} (4/5) + +\footnotesize + +## Initialisation + +- Avec le passage par **référence** on peut modifier un struct *en place*. +- Les champs sont accessible avec le sélecteur `->`{.C} + + ```C + void fraction_init(fraction_t *f, + int32_t num, int32_t denom) + { + // f a déjà été allouée + f->num = num; + f->denom = denom; + } + int main() { + fraction_t frac; // on alloue une fraction + fraction_init(&frac, 2, -1); // on l'initialise + } + ``` + +# Types composés: `struct`{.C} (5/5) + +\footnotesize + +## Initialisation version copie + +* On peut allouer une fraction, l'initialiser et le retourner. +* La valeur retournée peut être copiée dans une nouvelle structure. + + ```C + fraction_t fraction_create(int32_t num, int32_t denom) { + fraction_t f; + f.num = num; f.denom = denom; + return f; + } + int main() { + // on crée une fraction et on l'initialise + // en copiant la fraction créé par fraction_create + // deux allocation et une copie + fraction_t frac = fraction_create(2, -1); + } + ``` + +# Modification en place vs retour + +\footnotesize + +## Quelle est la différence entre `fraction_init` et `fraction_create`? + +```C +void fraction_init(fraction_t *f, int32_t num, int32_t denom); +fraction_t fraction_create(int32_t num, int32_t denom); +``` + +. . . + +* `fraction_init`{.C} modifie une fraction **déjà ** allouée quelque part. +* `fraction_create`{.C} alloue une nouvelle fraction et la retourne. + +. . . + +## Quelle impact sur les performances? + +. . . + +* `init`: une allocation et modification des données. +* `create`: deux allocation, une modification et une copie. +* Important pour des structures contenance *beaucoup* de données. + +# Précision + +## Différence avec les nombres à virgule? + +. . . + +* Les fractions ont une représentation **exacte**, + +. . . + +* Valeur min/max sont `INT32_MIN` / `INT32_MAX`, + +. . . + +* Limites sur les valeurs des `num`, `denom` possibles sont les `int32_t` qui peuvent être vite atteintes même pour des "petits" nombres. +\begin{align*} +&\underbrace{\frac{1002583}{1002584}}_{\sim 0.9999990025773402}+\underbrace{\frac{1005359}{1005358}}_{\sim 1.0000009946705553}\\ +&=\frac{1002583\cdot 1005358+1002584\cdot 1005359}{1002584\cdot 1005358}\\ +&=\underbrace{\frac{2015911687370}{1007955845072}}_{\sim 1.9999999972478952} +\end{align*} +* En réalité on a un dépassement de capacité: +\begin{align*} +\frac{1572025546}{-1361469488}\sim -1.1546535268368792. +\end{align*} + + -- GitLab