精華區beta C_and_CPP 關於我們 聯絡資訊
前些日子由於 term project 的關係看了不少有關 STL 的資料 這幾天想到一個不關語法的問題 在實際的運用上、用過的人覺得 STL 帶給你們什麼看法呢?(實用上) 龍龍 -- 你是一位聰明人嗎?如果是,你該記住,你的聰明是跟那些人學來的, 然後在適當的地點,適當的時間,輕輕的對那人說:這是你教我的。 聲音要輕,而且只告訴他一個人。 摘錄自"牧羊少年奇幻之旅" -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: DickG.m5.ntu.ed > -------------------------------------------------------------------------- < 作者: DeanL (格物致知) 看板: C_and_CPP 標題: Re: [STL] 大夥兒的看法 時間: Wed Feb 24 22:08:53 1999 ※ 引述《cying (應)》之銘言: : ※ 引述《hotball (哲哲魚)》之銘言: : : 讓程式變短……縮短開發時間…… : : Very good for lazy guys like me... : 編譯速度變慢, debug變困難(因debug symbol too long, truncated) : 程式變漂亮.... 看久了之後其實大致上就能抓出那一長串err msg的真義 希望下一代的compiler能夠簡化err msg,不過好像有一點困難.... 另外,在某些ocmpiler不會truncate err msg STL能讓功力不是那麼夠的人寫出想寫的程式 讓功力夠的人偷懶。 > -------------------------------------------------------------------------- < 作者: hotball (哲哲魚) 看板: C_and_CPP 標題: Re: [STL] 大夥兒的看法 時間: Thu Feb 25 01:48:27 1999 ※ 引述《DeanL (格物致知)》之銘言: : ※ 引述《cying (應)》之銘言: : : 編譯速度變慢, debug變困難(因debug symbol too long, truncated) : : 程式變漂亮.... : 看久了之後其實大致上就能抓出那一長串err msg的真義 : 希望下一代的compiler能夠簡化err msg,不過好像有一點困難.... : 另外,在某些ocmpiler不會truncate err msg : STL能讓功力不是那麼夠的人寫出想寫的程式 : 讓功力夠的人偷懶。 There are still some problems which are hard to solve... The "long error message" and "long symbol" issues are much easier to solve. A simple aliasing system should be fine (like "typedef" or something similar) But other problems are not this easy. For an example, a "class viewer" or "container viewer" is quite important at debugging (at least for some people), but to do such viewers, the compiler have to know something about the container, and organize the output well. For an example, it will be nice to "watch" 'a[10]' when 'a' is a vector or "watch" a list directly... Of course, this is not really a big issue for those who don't use debugger at all... Other problems, like "longer compile time", "bigger binary code", etc. are not very important now. > -------------------------------------------------------------------------- < 作者: cying (應) 看板: C_and_CPP 標題: Re: [STL] 大夥兒的看法 時間: Thu Feb 25 12:45:38 1999 ※ 引述《hotball (哲哲魚)》之銘言: : ※ 引述《DeanL (格物致知)》之銘言: : : 看久了之後其實大致上就能抓出那一長串err msg的真義 : : 希望下一代的compiler能夠簡化err msg,不過好像有一點困難.... : : 另外,在某些ocmpiler不會truncate err msg : : STL能讓功力不是那麼夠的人寫出想寫的程式 : : 讓功力夠的人偷懶。 : But other problems are not this easy. For an example, a "class viewer" : or "container viewer" is quite important at debugging (at least for : some people), but to do such viewers, the compiler have to know something : about the container, and organize the output well. : For an example, it will be nice to "watch" 'a[10]' when 'a' is a vector or : "watch" a list directly... I have some way to work around the current situation. Since the debugger could call functions inside the program to be debugged, you could write a special function that generates debugging information and put a watch to that function in the watch view. For example, a vector debug function might be something like this: template <class T> char *see(const vector<T> &a) { static char buf[...] clear buf for all element in a do concatenate see(a[i]) to buf return buf; } then implements individual "see" function to different types. Such as: char *see(int a) {...} char *see(const string &a) {...} The watch of this function will then determine the sub-type of the vector automatically what you see the watch. (Don't forget that function overloading is an important feature of C++. Use it well!) If you have a vector of strings, you might see somethings like this in the watch view: a: { "john", "mary", "ric" } This debug information is all generated by yourself. Ain't it a very good idea? Another issue with this method is that the linker sometimes eliminates unused symbol automatically. But you could do some dirty work to work around this problem: to write a useless code that calls the function you will need at runtime: void main() { unuse_funcs(); ... ... } void unuse_funcs() { vector<vector<vector<string> > > a; int b; see(a); see(b); } Note that the line "see(a)" actually propagates to several functions: see(const vector<vector<vector<string> &a) see(const vector<vector<string>> &a) see(const vector<string> &a) see(const string &a) So that an extra line to use see(const string&) won't be necessary. It's a simple trick. An important issue is that the buffer to return must be static, otherwise the watch view may cause an access violation when attempting to show a buffer that already be destroy by the function (since it's in the stack.) In many situation, a single static buffer might not enough because you might put several watch call to a single "see function". Using implementation introduced above will cause the buffer to be re-written each watch call. To work around this problem, you may use a "re-usable" buffer such as a circular-array. When the space is running out, the oldest one will be overwritten: typedef char watchBuf[100]; watchBuf bufs[maxBufs]; int bufCursor; char *applyBuffer() { char *result = bufs[bufCursor]; bufCursor ++; if (bufCursor >= maxBufs) bufCursor = 0; return result; } -- Chaos is the best description of the constant state of human society. Therefore, dynamic balance is required for us to to survive when vital fault occurrs. So in the society, we don't chase for peace and order, but existence and survival, instead. -- ※ 發信站: 批踢踢實業坊(ptt.twbbs.org) ◆ From: LSD.cc.ntu.edu.