鄭余玄

@chengscott

Joined on Aug 19, 2016

  • # common bugs 鄭余玄 補充:關於為定義行為介紹,可以參考:https://blog.regehr.org/archives/213 ## Problem 1 1. (Segmentation fault) - `char *strtok(char *restrict s1, const char *restrict s2);` 函式會修改到 `s1` 所指到的字串。 - `"this is a string"` 是一個 string literals 會分配於 static storage (C99 [6.4.5]),若嘗試修改內容則會導致未定義行為。 - `char *start = "this is a string";` 的`start` 是指向 static storage 的一個指標,因此編譯器不會提出存取警告,而是因為執行期間修改 string literals 造成未定義行為。 - `char start[] = "this is a string";` 中 `start` 是 `char[]` 型態語意會將資料分配於 stack 中(編譯器將
     Like  Bookmark