A clever new bag uses sunlight to power gadgets. The technical innovation is really cool. Here’s a cool design: A backpack that uses solar energy to charge portable electronic devices, my notebook especially. Voltaic Systems has been making these solar bags for many years now. Dubbed “portable solar power generators,” Voltaic’s bags have lightweight solar panels embedded in the framework. Inside are power connectors compatible with most mobile phones and MP3 players, as well as a backup battery to save surplus power for cloudy days. Voltaic’s newest bag, the Generator, is powerful enough to charge a laptop computer. At US$200 for the entry-level backpack, Voltaic’s bags are expensive. I think the solar bags idea will take off.
achi's Blog
Thursday, July 10, 2008
Tuesday, July 8, 2008
Talked to Katie
A girl walked out of a bookstore. She had many books. She walked into me. We both fell down. She said:"I'm sorry". And I said:"It's OK. Wow, you have a lot of books!" She said: " I am a new student at Yuan Ze University this year". I said:"And you are from American." She said : "Yes. How do you know?" I said:"You talk like an American!" She said:"Oh, right. My name is Katie." I said:"Well, Katie, welcome to Taiwan!"
I was excited today.
I was excited today.
Wednesday, July 2, 2008
Understanding Complicated const Type Declarations
C++ Primer 4/e in 4.2. Introducing Pointers there is an another advice:『Part of the problem in reading const declarations arises because the const can go either before or after the type: string const s1; // s1 and s2 have same type,
const string s2; // they’re both strings that are const
When writing const definitions using typedefs, the fact that the const can precede the type can lead to confusion as to the actual type being defined:
string s;
typedef string *pstring;
const pstring cstr1 = &s; // written this way the type
is obscured
pstring const cstr2 = &s; // all three decreations are
the same type
string *const cstr3 = &s; // they’re all const pointers
to string
Putting the const after pstring and reading the declaration from right to left makes it clearer that cstr2 is a const pstring, which in turn is a const pointer to string.
Unfortunately, most readers of C++ programs expect to see the const before the type. As a result, it is probably a good idea to put the const first, respecting common practice. But it can be helpful in understanding declarations to rewrite them to put the const after the type.』
Chinese translation is said:『閱讀const宣告式時,部份問題出在const可出現於型別之前或之後:
string const s1; // s1 和 s2 有著相同的型別,
const string s2; // 它門都是const strings
使用 typedefs 撰寫 const 定義式時,「const能夠出現於型別之前」這個事實容易困惑我們,到底定義了什麼型別:
string s;
typedef string *pstring;
const pstring cstr1 = &s; // 這麼寫會使型別晦澀不明
pstring const cstr2 = &s; // 三個宣告都是同一個型別
string *const cstr3 = &s; // 它們都是 const pointers to string
把 const 放在 pstring 之後並由右向左閱讀,便能夠清楚地看到 cstr2 是個 const pstring,也就是 const pointer to strng。
不幸地是大多數 C++ 程式碼閱讀者都預期看到 const 出現在型別前面。因此,依照一般慣例先讓 const 出現或許是個好主意。但如果讓 const 出現在型別之後,對於宣告式的被理解度或許有幫助。』
I hope I seldem us const type. My head now is chaotic a little.
achi's Blog
const string s2; // they’re both strings that are const
When writing const definitions using typedefs, the fact that the const can precede the type can lead to confusion as to the actual type being defined:
string s;
typedef string *pstring;
const pstring cstr1 = &s; // written this way the type
is obscured
pstring const cstr2 = &s; // all three decreations are
the same type
string *const cstr3 = &s; // they’re all const pointers
to string
Putting the const after pstring and reading the declaration from right to left makes it clearer that cstr2 is a const pstring, which in turn is a const pointer to string.
Unfortunately, most readers of C++ programs expect to see the const before the type. As a result, it is probably a good idea to put the const first, respecting common practice. But it can be helpful in understanding declarations to rewrite them to put the const after the type.』
Chinese translation is said:『閱讀const宣告式時,部份問題出在const可出現於型別之前或之後:
string const s1; // s1 和 s2 有著相同的型別,
const string s2; // 它門都是const strings
使用 typedefs 撰寫 const 定義式時,「const能夠出現於型別之前」這個事實容易困惑我們,到底定義了什麼型別:
string s;
typedef string *pstring;
const pstring cstr1 = &s; // 這麼寫會使型別晦澀不明
pstring const cstr2 = &s; // 三個宣告都是同一個型別
string *const cstr3 = &s; // 它們都是 const pointers to string
把 const 放在 pstring 之後並由右向左閱讀,便能夠清楚地看到 cstr2 是個 const pstring,也就是 const pointer to strng。
不幸地是大多數 C++ 程式碼閱讀者都預期看到 const 出現在型別前面。因此,依照一般慣例先讓 const 出現或許是個好主意。但如果讓 const 出現在型別之後,對於宣告式的被理解度或許有幫助。』
I hope I seldem us const type. My head now is chaotic a little.
achi's Blog
Tuesday, July 1, 2008
Avoid Pointers and Arrays
C++ Primer 4/e in 4.2. Introducing Pointers there is a advice:『Pointers and arrays are surprisingly error-prone. Part of the problem is conceptual: Pointers are used for low-level manipulations and it is easy to make bookkeeping mistakes. Other problems arise because of the syntax, particularly the declaration syntax used with pointers.
Many useful programs can be written without needing to use arrays or pointers. Instead, modern C++ programs should use vectors and iterators to replace general arrays and strings to replace C-style array-based character strings.』
Chinese translation is said::『Pointers 和 Arrays 容易出錯的程度令人驚訝。部份問題是概念性的:pointers用來進行低階操作,因此容易犯下簿記錯誤(bookkeeping mistakes)。另一個問題出在語法,特別是pointers的宣告語法。
很多有用的程式並不需要使用arrays 或pointers就能寫成。現今的C++程式應該使用vectors 和iterators取代arrays,並使用strings取代C 風格的、以array為基礎的字元字串。』
It seems I will more and more like C++.Little using pointers is a big gospel.Little using arrays needs time to change.
achi's Blog
achi’s English Blog
Many useful programs can be written without needing to use arrays or pointers. Instead, modern C++ programs should use vectors and iterators to replace general arrays and strings to replace C-style array-based character strings.』
Chinese translation is said::『Pointers 和 Arrays 容易出錯的程度令人驚訝。部份問題是概念性的:pointers用來進行低階操作,因此容易犯下簿記錯誤(bookkeeping mistakes)。另一個問題出在語法,特別是pointers的宣告語法。
很多有用的程式並不需要使用arrays 或pointers就能寫成。現今的C++程式應該使用vectors 和iterators取代arrays,並使用strings取代C 風格的、以array為基礎的字元字串。』
It seems I will more and more like C++.Little using pointers is a big gospel.Little using arrays needs time to change.
achi's Blog
achi’s English Blog
Monday, June 30, 2008
Arrays Are Fixed Size
C++ Primer 4/e in 4.1. Arrays there is a beware:『Some compilers allow array assignment as a compiler extension. If you intend to run a given program on more than one compiler, it is usually a good idea to avoid using nonstandard compiler-specific features such as array assignment.』
Another a caution:『Unlike the vector type, there is no push_back or other operation to add elements to the array. Once we define an array, we cannot add elements to it.
If we must add elements to the array, then we must manage the memory ourselves. We have to ask the system for new storage to hold the larger array and copy the existing elements into that new storage. We’ll see how to do so in Section 4.3.1 (p. 134).』
Chinese Translation is said:『有些編譯器允許array賦值操作,視為一種編譯器擴充功能。如果你希望程式通過一個以上的編譯器,最好避免使用非標準的編譯器特有性質,例如這裡所說的array賦值操作。
不同於vector,array並沒有push_back()或其他用來增添元素的操作。一旦我們定義了一個array,就不能再擴展它。
如果一定要為array添加元素(空間),就必須自我管理記憶體。我們必須向系統要求新空間以存放較大的array,然後複製現有元素到新空間去。』
At first array has not push_back supported it is not very convenient.
achi's Blog
Another a caution:『Unlike the vector type, there is no push_back or other operation to add elements to the array. Once we define an array, we cannot add elements to it.
If we must add elements to the array, then we must manage the memory ourselves. We have to ask the system for new storage to hold the larger array and copy the existing elements into that new storage. We’ll see how to do so in Section 4.3.1 (p. 134).』
Chinese Translation is said:『有些編譯器允許array賦值操作,視為一種編譯器擴充功能。如果你希望程式通過一個以上的編譯器,最好避免使用非標準的編譯器特有性質,例如這裡所說的array賦值操作。
不同於vector,array並沒有push_back()或其他用來增添元素的操作。一旦我們定義了一個array,就不能再擴展它。
如果一定要為array添加元素(空間),就必須自我管理記憶體。我們必須向系統要求新空間以存放較大的array,然後複製現有元素到新空間去。』
At first array has not push_back supported it is not very convenient.
achi's Blog
Sunday, June 29, 2008
Iterators and Iterator Types
C++ Primer 4/e 3.4. Introducing Iterators ther is a terminology:『When first encountered, the nomenclature around iterators can be confusing. In part the confusion arises because the same term, iterator, is used to refer to two things. We speak generally of the concept of an iterator, and we speak specifically of a concrete iterator type defined by a container, such as vector.
What’s important to understand is that there is a collection of types that serve as iterators. These types are related conceptually. We refer to a type as an iterator if it supports a certain set of actions. Those actions let us navigate among the elements of a container and let us access the value of those elements.
Each container class defines its own iterator type that can be used to access the elements in the container. That is, each container defines a type named iterator, and that type supports the actions of an (conceptual) iterator.』
Chinese translationis said:『第一次遭遇術語iterators時可能會感到困惑。部份原因是同一個術語iterator可用來指兩件事。可以指一般的iterator概念,也可以指某容器(例如vector)所定義的具象iterator型別。
一件必須瞭解的重要事情是,有一大群型別可作為iterators使用。這些型別在概念上彼此關聯。當一個型別支援某「特定動作集」時我們稱它為iterator;它讓我們得以尋訪容器元素並存取元素值。
每個做為容器的class都定義有自己的iterator型別,可用來存取容器元素。也就是說每個容器都定意有一個名為iterator的型別,該型別支援(概念上的)iterator所能採取的動作。』
What is concrete ?I don't understand.
achi's Blog
What’s important to understand is that there is a collection of types that serve as iterators. These types are related conceptually. We refer to a type as an iterator if it supports a certain set of actions. Those actions let us navigate among the elements of a container and let us access the value of those elements.
Each container class defines its own iterator type that can be used to access the elements in the container. That is, each container defines a type named iterator, and that type supports the actions of an (conceptual) iterator.』
Chinese translationis said:『第一次遭遇術語iterators時可能會感到困惑。部份原因是同一個術語iterator可用來指兩件事。可以指一般的iterator概念,也可以指某容器(例如vector
一件必須瞭解的重要事情是,有一大群型別可作為iterators使用。這些型別在概念上彼此關聯。當一個型別支援某「特定動作集」時我們稱它為iterator;它讓我們得以尋訪容器元素並存取元素值。
每個做為容器的class都定義有自己的iterator型別,可用來存取容器元素。也就是說每個容器都定意有一個名為iterator的型別,該型別支援(概念上的)iterator所能採取的動作。』
What is concrete ?I don't understand.
achi's Blog
Thursday, June 26, 2008
Only Subscript Elements that Are Known to Exist!
C++ Primer 4/e in 3.4. Introducing Iterators there is a warning:『It is crucially important to understand that we may use the subscript operator, (the [] operator), to fetch only elements that actually exist. For example,
vector ivec; // empty vector
cout <<> ivec2(10); // vector with 10 elements
cout << ivec[10]; //error
Chinese translation is said:『我們只能以subscript運算子([])取出實際存在的元素。這一點十分重要。例如:
vector ivec; // 空的 vector
cout <<> ivec2(10); // vector 內含 10 個元素
cout << ivec[10]; // 錯誤: ivec 的元素編號是0到9
擷取不存在的元素會造成執行期錯誤。編譯器並不保證能偵測出大部分此類錯誤。這個程式的執行結果無法確定,因為「擷取不存在元素」是一種不明確的行為,其結果視編譯器而不同,但幾乎可以確定會在執行期出現某種有趣的錯誤。
這個警告亦可套用於任何使用下標的時候,例如對string或(很快會看到)對內建的array取下標。
不幸的是,企圖以下標存取不存在的元素是極常見且致命的編程錯誤。所謂緩衝區上限溢位(buffer overflow)錯誤就是以下標存取不確定元素的結果。這種臭蟲是形成PC程式及其他應用程式安全問題的最常見原因。』
This is a good warning, especially when we from VB microsoft's series to C series using array often mistake the array start from 0 or 1 .
achi's Blog
vector
cout <<> ivec2(10); // vector with 10 elements
cout << ivec[10]; //error
Chinese translation is said:『我們只能以subscript運算子([])取出實際存在的元素。這一點十分重要。例如:
vector
cout <<> ivec2(10); // vector 內含 10 個元素
cout << ivec[10]; // 錯誤: ivec 的元素編號是0到9
擷取不存在的元素會造成執行期錯誤。編譯器並不保證能偵測出大部分此類錯誤。這個程式的執行結果無法確定,因為「擷取不存在元素」是一種不明確的行為,其結果視編譯器而不同,但幾乎可以確定會在執行期出現某種有趣的錯誤。
這個警告亦可套用於任何使用下標的時候,例如對string或(很快會看到)對內建的array取下標。
不幸的是,企圖以下標存取不存在的元素是極常見且致命的編程錯誤。所謂緩衝區上限溢位(buffer overflow)錯誤就是以下標存取不確定元素的結果。這種臭蟲是形成PC程式及其他應用程式安全問題的最常見原因。』
This is a good warning, especially when we from VB microsoft's series to C series using array often mistake the array start from 0 or 1 .
achi's Blog
Subscribe to:
Posts (Atom)