Nekrolm / ubbook

Путеводитель C++ программиста по неопределенному поведению
1.08k stars 52 forks source link

Implementation-specific ODR violations with `-static` #62

Closed yeputons closed 2 years ago

yeputons commented 3 years ago

https://stackoverflow.com/questions/69424363/is-it-allowed-to-name-a-global-variable-read-or-malloc-in-c

Even on Windows you have to know that read is an internal function which is used by cin, otherwise the following with crash when compiled with -static:

#include <iostream>
int read;
int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin >> read;
}

Inspired by real world example at https://codeforces.com/blog/entry/95574

Nekrolm commented 3 years ago

Will be covered in chapter related to reserved identifiers.