C語言裡的side effect是什麼意思?

時間 2021-06-01 19:07:34

1樓:

樓上的朋友的回答都不是很全面(或者乾脆不正確...),感興趣的朋友可以參考如下幾個鏈結 :)

[1]. C++ Reference Guide[2]. Stack Overflow: What exactly is a 'side-effect' in C++?

[3]. Stack Exchange:What is a "side effect?"

2樓:薛非

side effect是關於計算(Evaluation)表示式的效應之一。譬如 int i; 計算 i = 3 這個表示式會得到乙個值3,但同時變數i也被賦值了,這賦值的效應就是side effect。不是所有計算都有副效應,例如計算2+3 得到值5,但沒有side effect。

side effect的標準定義是:Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects,which are changes in the state of the execution environment.

3樓:彭嘉

Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression in general includes both value computations and initiation of side effects. Value computation for an lvalue expression includes determining the identity of the designated object.

from: ansi-C99

關於C語言裡setvbuf和setbuf的疑問?

PJHubs 其實,不單單只是檔案的使用,而是說與緩衝池打交道的場景下都有必要去使用,當然,這是充分不必要條件。尤其你是要把 東西 從外部儲存器中移交給程式使用,當你這段程式多次反覆的呼叫後,系統會將其放入cache 高速緩衝儲存器 中,為啥要放呢?這個場景就跟題主問的問題類似了。之所以要先把檔案先...

C語言裡a b a c a b c 這個怎麼該判斷?

三目表示式語法分析時是深度優先遞迴,遇到第乙個問號時,從當前字元位置開始,遞迴解析新的表示式,然後遞迴出表示式a在編譯原理課程中考這樣的題目不為過,但在C語言中考這樣的題目就太坑了。 derek gong 你把 當做一對括號 習慣了括號匹配的話哪個 和哪個 配對一目了然 因為它們的匹配規則一致所以給...

C語言裡pthread到底該怎麼用呢?

醉臥沙場 Please,man pthread create PTHREAD CREATE 3Linux Programmer s ManualPTHREAD CREATE 3 NAME pthread create create a new thread SYNOPSIS include int ...