Re: 5 more simple patches for usr.bin/make

看板DFBSD_submit作者時間21年前 (2004/11/14 04:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串8/8 (看更多)
:One thing you can improve is the use of static strings with write. :E.g. instead of write(2, "BLA", 3); something either like :const char msg_bla[] = "BLA"; :write(2, msg_bla, sizeof(msg_bla)); : :or : :#define WRITE(fd, str) write(fd, str, sizeof(str)) : :would be useful, the hardwired string length is evil. Be careful though, :the sizeof only works with char[], not char * ! : :Joerg Well, remember that a string assignment to a char[] array includes the terminating \0.. so that will not work quite the way you wrote it. Just do this: const char * const msg = "BLA"; write(fd, msg, strlen(msg)); GCC will calculate the strlen() for you at compile-time. -Matt Matthew Dillon <dillon@backplane.com>
文章代碼(AID): #11bcWZ00 (DFBSD_submit)
討論串 (同標題文章)
文章代碼(AID): #11bcWZ00 (DFBSD_submit)