C++ में undefined, unspecified और implementation-defined behavior के बीच क्या अंतर है?
नमस्ते साथियों! मैं लगभग छह महीने से C++ में लिख रहा हूँ, और लगातार undefined behavior (UB), unspecified behavior और implementation-defined behavior शब्दों का सामना करता हूँ। मैं अक्सर फोरम पर पढ़ता हूँ कि UB एक "डरावनी चीज़" है, जिसके कारण प्रोग्राम "फट" सकता है, लेकिन मैं इन तीनों अवधारणाओं के बीच अंतर पूरी तरह से नहीं समझता।
उदाहरण के लिए, मैं जानता हूँ कि null pointer को dereference करना UB है। लेकिन function arguments के evaluation order के बारे में क्या? मैंने यह कोड लिखा:
```cpp
#include
int foo() { std::cout << "foo "; return 1; }
int bar() { std::cout << "bar "; return 2; }
int main() {
int x = foo() + bar(); // आउटपुट का क्रम क्या होगा?
std::cout << x;
return 0;
}
```
विभिन्न compilers (GCC और Clang) में मुझे अलग-अलग आउटपुट मिले: कभी "foo bar 3", कभी "bar foo 3"। क