C++ Primer 4/e in 2.3. Variables there is a caution :『
Using an uninitialized object is a common program error, and one that is often difficult to uncover. The compiler is not required to detect a use of an uninitialized variable, although many will warn about at least some uses of uninitialized variables. However, no compiler can detect all uses of uninitialized variables.
Sometimes, we’re lucky and using an uninitialized variable results in an immediate crash at run time. Once we track down the location of the crash, it is usually pretty easy to see that the variable was not properly initialized.
Other times, the program completes but produces erroneous results. Even worse, the results can appear correct when we run our program on one machine but fail on another. Adding code to the program in an unrelated location can cause what we thought was a correct program to suddenly start to produce incorrect results.
The problem is that uninitialized variables actually do have a value. The compiler puts the variable somewhere in memory and treats whatever bit pattern was in that memory as the variable’s initial state. When interpreted as an integral value, any bit pattern is a legitimate valuealthough the value is unlikely to be one that the programmer intended. Because the value is legal, using it is unlikely to lead to a crash. What it is likely to do is lead to incorrect execution and/or incorrect calculation.』
Chinese translation is said:『使用未初始化物件是個常見的程式錯誤,也是很難發現的一種錯誤。編譯器並沒有要求偵測「未初始化變數的使用」。雖然很多編譯器會對某些未初始化變數的使用發出警告,然而沒有任何編譯器能夠偵測出所有未初始化變數的使用。
有時候我們很幸運地在使用一個未初始化變數時立刻於執行期當掉。只要追蹤崩潰點,通常很容易就可以發現變數未被適當初始化。
但很多時候程式順利執行,並產生錯誤結果。更糟的是在某一台機器上執行產生正確的結果,換到另一台卻出錯。如果急病亂投醫,在不相干位置加入程式碼,很可能造成原本正確的程式突然開始產生不正確的結果。
問題在於未初始化變數其實有一個值。編譯器首先把變數「放在」記憶體某處,然後把那塊記憶體的bit樣式(無論它是什麼)當作那個變數的初值。任何bit樣式(bit pattern)被當作整數來詮釋時都是合理的 - 雖然那不是程式員所希望得到的值。因為其值合法,所以使用他不太容易造成程式崩潰。比較可能的是導致不正確的執行和(或)不正確的計算結果。』
When using PHP I often not pay attention to initialie variables, but seldom get errors so I oftn forgot to initialize variables. Especially turn back to code using C or C++, I frequently get errors, so it is a good warning.
Sunday, June 22, 2008
Friday, June 20, 2008
India Broadband
I live in Taiwan and I always use Chunghwa Telecom’s Internet service providers to surf internet.Although I think is expensive and I have no idea to choice another company’s services.And I found India Broadband the site is a forum.So you can see many posts to dicuss about ISPs with news, views and reviews of Internet service providers and plans offered.Although is not useful to me in Taiwan.But if you are in India it may be useful to you.
achi's Blog
achi's Blog
The Real Blogger Status: Adding A Google Sitemap To Your Blog
The Real Blogger Status: Adding A Google Sitemap To Your Blog
Payperpost said my blog is not being indexed by search engines.And they give me some suggestions.But some steps need sitemap so I find the post to help me add a Google sitemap to my blog.This is helpful to me.I hope I can success to submit payperpost.
achi's Blog
Payperpost said my blog is not being indexed by search engines.And they give me some suggestions.But some steps need sitemap so I find the post to help me add a Google sitemap to my blog.This is helpful to me.I hope I can success to submit payperpost.
achi's Blog
mysql trigger example
I want to update my situation :
If modified content of the content field is different before and after then the trigger is activate, the syntax as blew:
DELIMITER
CREATE TRIGGER audit_content BEFORE UPDATE ON conten
FOR EACH ROW BEGINIF OLD.content <> NEW.content THEN
INSERT INTO content_audit SET content_id = OLD.id,before_value = OLD.content,after_value = NEW.content;
END IF;
END;
This is too cool.If I have this function, I can go on my work.
achi's Blog
If modified content of the content field is different before and after then the trigger is activate, the syntax as blew:
DELIMITER
CREATE TRIGGER audit_content BEFORE UPDATE ON conten
FOR EACH ROW BEGINIF OLD.content <> NEW.content THEN
INSERT INTO content_audit SET content_id = OLD.id,before_value = OLD.content,after_value = NEW.content;
END IF;
END;
This is too cool.If I have this function, I can go on my work.
achi's Blog
Thursday, June 19, 2008
Temporary Objects
http://urza.wordpress.com/2008/06/08/temporary-objects/
This is talk about C++ primer 4th Edtion 7.3. The return Statement. I can link this and when I go to chapter 7.I can review this post.
achi's blog
This is talk about C++ primer 4th Edtion 7.3. The return Statement. I can link this and when I go to chapter 7.I can review this post.
achi's blog
Strong Static Typing
from Strong Static Typing
C++ Primer 4/e in 2.3. Variables there is a key concept:『
C++ is a statically typed language, which means that types are checked at compile time. The process by which types are checked is referred to as type-checking.
In most languages, the type of an object constrains the operations that the object can perform. If the type does not support a given operation, then an object of that type cannot perform that operation.
In C++, whether an operation is legal or not is checked at compile time. When we write an expression, the compiler checks that the objects used in the expression are used in ways that are defined by the type of the objects. If not, the compiler generates an error message; an executable file is not produced.
As our programs, and the types we use, get more complicated, we’ll see that static type checking helps find bugs in our programs earlier. A consequence of static checking is that the type of every entity used in our programs must be known to the compiler. Hence, we must define the type of a variable before we can use that variable in our programs.』
The Chinese translation said:『C++是個靜態型別語言,意思是型別在編譯期被檢查。型別被檢查的過程稱為型別檢驗。
在大部分語言中,物件的型別限制了該物件能夠執行的操作。如果物件的型別不支援某個操作,這個物件就不能執行那項操作。
在C++中,一個操作是否合法,將在編譯期被檢查。當我們寫下一個算式,編譯器會檢查算式裡用到的物件是否按其型別所定義的方法來使用。如果不是,編譯器會產出一個錯誤訊息,不產出可執行檔。
隨著我們的程式和使用的型別愈來愈複雜,我們會看到,靜態型別檢驗有助於早期找出程式臭蟲。靜態檢驗的一個結果是,程式用到的每一個物體的型別都必須為編譯器所知。因此我們必須在程式使用某個變數之前先定義好該變數的型別。』
I coded a long time with PHP.And I think PHP has no strong static typing.So when I return to code with C or C++, I dies very much miserably.
C++ Primer 4/e in 2.3. Variables there is a key concept:『
C++ is a statically typed language, which means that types are checked at compile time. The process by which types are checked is referred to as type-checking.
In most languages, the type of an object constrains the operations that the object can perform. If the type does not support a given operation, then an object of that type cannot perform that operation.
In C++, whether an operation is legal or not is checked at compile time. When we write an expression, the compiler checks that the objects used in the expression are used in ways that are defined by the type of the objects. If not, the compiler generates an error message; an executable file is not produced.
As our programs, and the types we use, get more complicated, we’ll see that static type checking helps find bugs in our programs earlier. A consequence of static checking is that the type of every entity used in our programs must be known to the compiler. Hence, we must define the type of a variable before we can use that variable in our programs.』
The Chinese translation said:『C++是個靜態型別語言,意思是型別在編譯期被檢查。型別被檢查的過程稱為型別檢驗。
在大部分語言中,物件的型別限制了該物件能夠執行的操作。如果物件的型別不支援某個操作,這個物件就不能執行那項操作。
在C++中,一個操作是否合法,將在編譯期被檢查。當我們寫下一個算式,編譯器會檢查算式裡用到的物件是否按其型別所定義的方法來使用。如果不是,編譯器會產出一個錯誤訊息,不產出可執行檔。
隨著我們的程式和使用的型別愈來愈複雜,我們會看到,靜態型別檢驗有助於早期找出程式臭蟲。靜態檢驗的一個結果是,程式用到的每一個物體的型別都必須為編譯器所知。因此我們必須在程式使用某個變數之前先定義好該變數的型別。』
I coded a long time with PHP.And I think PHP has no strong static typing.So when I return to code with C or C++, I dies very much miserably.
Break The Rulez: C++ Primer 4th Edition
Break The Rulez: C++ Primer 4th Edition
I like 4th Edition more than 3rd Edition.Because I think 4th Edition is easy reading for me.
achi's blog
I like 4th Edition more than 3rd Edition.Because I think 4th Edition is easy reading for me.
achi's blog
Subscribe to:
Posts (Atom)