作者:
sb5471 (sb)
2015-06-25 00:28:39開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
OS : Ubuntu 14.04 LTS
toolchain : arm-none-eabi
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
porting 他人程式, compile 後出現 warning, 想將它移除.
compile msg 片段: http://pastie.org/10256821
該程式裡有很多 "inline function + 裡面含 static variable" 的寫法
舉例: a.c & b.c & c.c 裡皆有使用到 my_func()
inline void my_func(void)
{
static int s_var = 1;
do_something(); // 會使 s_var 值發生改變
}
> arm-none-eabi-gcc main.c a.c b.c c.c
Q1: warning msg 有 "[enabled by default]" 字樣.
意思是不是 arm-none-eabi-gcc 會自動將 my_func() 改成這樣:
=> static inline void my_func(void) ??
Q2: 承上, 這代表 build 出來的 a.c & b.c & c.c 裡, 都有各自一份
s_var 嗎??
Q3: 如果我希望 a.c & b.c & c.c (或是說, 最終的執行檔 a.out)
只 share 同一份 s_var 的話, 請問要怎麼改?
a). 將 s_var 宣告在 my_func() 外??
b). 將 inline 拿掉 ?
c). 還是, 根本就做不到 ??
餵入的資料(Input):
無
預期的正確結果(Expected Output):
無
錯誤結果(Wrong Output):
無
程式碼(Code):(請善用置底文網頁, 記得排版)
無
補充說明(Supplement):
作者:
sb5471 (sb)
2015-06-25 00:34:00弄一個d.c, 然後 my_func的inline拿掉+移到 d.c, 是這樣??如果考慮效能, 希望能保留"inline"的能力, 也就是build 出來的 code, 盡量減少 function call 的情況有辦法做到嗎?