--- title: Sunifdef Intro tags: Sunifdef, Slides description: the slide to introduct "Sunifdef". --- <!-- .slide: data-background="#33383E" --> # ++Sunifdef Intro++ Jerry Chen <!-- Put the link to this slide here so people can follow --> slide: https://hackmd.io/@AManTw/Hk-ys3IXS --- <!-- .slide: data-background="#C0C0C0" --> ## ++什麼是 Sunifdef++ --- <!-- .slide: data-background="#C0C0C0" --> - 移除C/C++程式碼中,不需要的symbol - 可一次指定不同值的symbol - 支援#if...#ifdef... --- <!-- .slide: data-background="#C0C0C0" --> ## ++#if & #ifdef++ <br> <style> code.orange { color: #B27300 !important; } </style> - <code class="orange">#if</code>  : 後面接的是判斷式 - <code class="orange">#ifdef</code> : 後面則是接上一個marco --- <!-- .slide: data-background="#C0C0C0" --> ```cpp #if 1 ... #if (MAX > 10)||(MAX < 5) ... #ifdef RLC_HOST ... #ifndef RLC_HOST ... ``` --- <!-- .slide: data-background="#C0C0C0" --> ## ++常用參數-1++ | Var. | 展開範例 | 用途 | | :---: | :---: | :---: | | f | -fFILE | 從FILE讀取 symbol| | r | - -replace | 將結果覆寫至原檔案 | | D | - -define SYMBOL | 要保留的 SYMBOL | | U | - -undef SYMBOL | 不保留的 SYMBOL | --- <!-- .slide: data-background="#C0C0C0" --> D:代表選擇該symbol是有定義的情況 U:代表選擇該symbol是沒有定義的情況 ==> 單純去除symbol外殼的#if #endif => 選 D ==> 要將整塊symbol 包含程式刪除 => 選U --- <!-- .slide: data-background="#C0C0C0" --> ## ++常用參數-2++ | Var. | 展開範例 | 用途 | | :---: | :--- | :---: | | ne[d] | -ne[d] | 判斷#if的真假值 | | K | - -keepgoing | 錯誤發生時,繼續執行 | | l | - -line | 印出處理過的行數 | --- <!-- .slide: data-background="#C0C0C0" --> ## ++實際DEMO++ --- <!-- .slide: data-background="#C0C0C0" --> ```c= #include <stdio.h> #define _have_define int num = 1; void fn_if_zero() { if (num == 0 ) { printf("THis is 0\n"); } #if 0 else{ printf("Never Go here\n"); } #else else{ printf("GO here\n"); } #endif } void fn_not_defined() { if (num == 0 ){ printf("THis is 0\n"); } #ifndef no_define else{ printf("Never go here\n"); } #else else{ printf("no_define is go here \n"); } #endif } void fn_have_define() { if (num == 0 ) { printf("THis is 0\n"); } #ifdef _have_define else{ printf("_have_define Go here \n"); } #else else{ printf(" Never Go here\n"); } #endif } ``` --- <!-- .slide: data-background="#C0C0C0" --> 1. #if 0 ```bash= sunifdef -DDEFINE -ned --replace -l ifdef.c ``` 2. #ifndef ```bash=+ sunifdef -Dno_define --replace -l ifdef.c ``` 3. #ifdef ```bash=+ sunifdef -D_have_define --replace -l ifdef.c ``` --- <!-- .slide: data-background="#33383E" --> ### Thank you! :coffee:
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up