|Design| Benefits of using Macro

What is the Macro?
If you write as “#define” in your code, that is “Macro” .

Macro will handle by the preprocessor.
You can think Macro as a method to replace the String which appears in you code..

pros:
– run faster than writing as function

cons:
– occupy memories

concepts:
– there is no the concept of pointer in macro.
just “replacing the string”

An question:
What is the output of the following code?

#define macro_to_func(pp) ({printf("in Macro ...\n"); minus ;})

void do_something(int *a, int *b){
    printf("do_something\n");
    int c;
    c = *a + *b;
    printf("do_something %d \n", c);
}

int minus(int *a, int *b){
    printf("minus\n");
    int c;
    c = *a - *b +1;
    printf("minus a = %d \n", *a);
    printf("minus b = %d \n", *b);
    printf("minus %d \n", c);
    return c;
}

int main()
{
    int (*do_something)(int* c, int* d);
    //printf("fptr 1 do_something %p\n", &do_something);

    int m = -1;
    int n = 7;

    printf("do_something = macro_to_func\n");
    do_something = macro_to_func(pp);
    //printf("fptr minus %p\n", &minus);
    //printf("fptr 2 do_something %p\n", &do_something);
    if(do_something){
        printf("in IF!!\n");
        do_something(&m, &n); --------------------------->???
    }
    return 0;
}

Answer:

do_something = macro_to_func
in Macro …
in IF!!
minus
minus a = -1
minus b = 7
minus -7

Explanation:
“int (*do_something)” is a local function pointer.
In the macro, the macro_to_func will be replaced as “minus”, but do_something !!!

|Code| LLVM initial

One day, if you want to implement a module on the platform x86_64 for arm64, you will need to know the tool chain, “cross compiler”.
The famous modern compiler is LLVM.

Why should we understand the compiler?
– build for multi-platform
– improve the efficiency of your code
– …..

I have a conclusion for the developer whose library is under the user space.
Use suitable optimization provided by LLVM, and make your code readable.
Dazzle coding is meaningless.

你所不知道的 C 語言:編譯器和最佳化原理篇
[共筆] 不深不淺,帶你認識 LLVM
“編譯器 LLVM 淺淺玩” by Pokai Chang

|Jobs| Who is worthy of being called “Engineer” ?

The core competencies of engineer are
– never complain
– segmenting problems
hands-on problem solving
– not defeatist

You can win if you want.

If I am an interviewer, I just want to know ……
Will he/she want to solve problems?
Is he/she a defeatism?
Will he/she look down on other fields?
I don’t like whom disregard others.
It means he/she ignore details in him/her life.

|LTE| 開啟行動上網 ……

這篇會走一趟整個使用行動上網的流程,以及封包如何出去。
若想知道更多,可利用 > 後的關鍵字去做搜尋。

我們一開機,不是在飛航模式 ……
– UE 會向 NW 做 “initial attach”
包含:
> RRC connection (手機告訴網路說:我想要連線啦~基地台快醒來服務我)
> Attach request (我要送東西ㄛ~大概是一個包裹的大小,
         請幫忙聯絡車車來送貨)
> EMM 通知後端網路及認證 (電信商的櫃台忙著聯絡服務中心)
> RRC reconfiguration (開始配送貨車來服務客人送貨)

詳細流程可參考:
一分鐘快速了解手機如何傳送檔案


– Initial attach 之後,表示 UE 已經向網路拿到派發的 IP
– 這時候手機裡的 data service 會向 modem 取得 IP address
– 設定 Linux 裡的 “rmnet_data”、”DNS” ……
到此時,手機端的設定準備好了,建立連線完成。
但還沒有要送封包出去哦 ……

開始要送封包 ……
封包從 APP 開始,會經過:
– TCP
– IP
– MAC
– rmnet driver 走出去到網路端啦~
The packet flow, from userspace to kernel driver in Linux network stack

接下來就上到電信商給的車車載走囉!

LTE initial attach