Files
Kevin Thomas f62db776e1 Initial commit
2026-07-06 14:32:12 -04:00

63 lines
3.3 KiB
XML

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 800">
<style>
.bg{fill:#0a0a0f}.pnl{fill:#12121a;stroke:#1a1a2e}.hdr{fill:#12121a}
.title{font:bold 42px 'Courier New',monospace;fill:#00ff41}
.sub{font:bold 28px 'Courier New',monospace;fill:#00d4ff}
.txt{font:24px 'Courier New',monospace;fill:#c0c0c0}
.dim{font:20px 'Courier New',monospace;fill:#888}
.grn{font:bold 24px 'Courier New',monospace;fill:#00ff41}
.red{font:bold 24px 'Courier New',monospace;fill:#ff0040}
.cyn{font:bold 24px 'Courier New',monospace;fill:#00d4ff}
.amb{font:bold 24px 'Courier New',monospace;fill:#ffaa00}
.badge{stroke:#00ff41;rx:14}
</style>
<rect class="bg" width="1200" height="800"/>
<rect class="hdr" x="0" y="0" width="1200" height="100" rx="0"/>
<text class="title" x="600" y="52" text-anchor="middle">#define vs const</text>
<text class="dim" x="600" y="88" text-anchor="middle">Preprocessor Macros vs Constant Variables</text>
<!-- Left Panel: #define -->
<rect class="pnl" x="30" y="110" width="555" height="370" rx="8"/>
<text class="amb" x="50" y="145">#define FAV_NUM 42</text>
<rect x="50" y="160" width="515" height="140" rx="6" fill="#1a1a2e" stroke="#ffaa00" stroke-width="1"/>
<text class="txt" x="70" y="190">Preprocessor text replacement</text>
<text class="txt" x="70" y="220">Happens BEFORE compilation</text>
<text class="txt" x="70" y="250">No memory allocated</text>
<text class="txt" x="70" y="280">Cannot take address (&amp;)</text>
<text class="dim" x="50" y="325">In Binary:</text>
<rect x="50" y="335" width="515" height="55" rx="6" fill="#0a0a0f" stroke="#ffaa00" stroke-width="1"/>
<text class="grn" x="70" y="368">movs r1, #42 @ 0x2a</text>
<text class="dim" x="50" y="415">16-bit Thumb instruction</text>
<text class="dim" x="50" y="440">Value embedded as immediate</text>
<text class="dim" x="50" y="465">Compiler sees only "42"</text>
<!-- Right Panel: const -->
<rect class="pnl" x="615" y="110" width="555" height="370" rx="8"/>
<text class="cyn" x="635" y="145">const int OTHER_FAV_NUM=1337</text>
<rect x="635" y="160" width="515" height="140" rx="6" fill="#1a1a2e" stroke="#00d4ff" stroke-width="1"/>
<text class="txt" x="655" y="190">Creates real variable</text>
<text class="txt" x="655" y="220">Theoretically in .rodata</text>
<text class="txt" x="655" y="250">Has an address (if needed)</text>
<text class="txt" x="655" y="280">Type-checked by compiler</text>
<text class="dim" x="635" y="325">In Binary:</text>
<rect x="635" y="335" width="515" height="55" rx="6" fill="#0a0a0f" stroke="#00d4ff" stroke-width="1"/>
<text class="grn" x="655" y="368">movw r1, #1337 @ 0x539</text>
<text class="dim" x="635" y="415">32-bit Thumb-2 instruction</text>
<text class="dim" x="635" y="440">Also embedded as immediate!</text>
<text class="dim" x="635" y="465">Compiler optimized it away</text>
<!-- Bottom Panel: Key Insight -->
<rect class="pnl" x="30" y="500" width="1140" height="140" rx="8"/>
<text class="red" x="50" y="535">KEY INSIGHT:</text>
<text class="txt" x="265" y="535">Both ended up as instruction immediates!</text>
<text class="dim" x="50" y="570">The compiler saw &amp;OTHER_FAV_NUM is never used, so it</text>
<text class="dim" x="50" y="595">optimized const the same way as #define -- no memory load needed.</text>
<text class="amb" x="50" y="625">Lesson: const is a source-level concept -- not guaranteed in binary</text>
<!-- Footer -->
</svg>