Questions tagged [observable-behavior]

3 questions
11
votes
5 answers

Is printing an empty string observable behavior in C++?

In C++03 Standard observable behavior (1.9/6) includes calls to library I/O functions. Now I have this code: printf( "" ); which is formally a call to a library I/O function but has no effect. Is it observable behavior? Is the compiler allowed to…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
7
votes
1 answer

Does any change in program state constitute observable behavior?

Consider the two following programs: program one int main() { printf( "hello\n" ); } program two int main() { srand( 0 ); if( rand() ) { printf( "hello\n" ); } else { printf( "hello\n" ); } } Do they have the same…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
-1
votes
2 answers

Is this compiler optimization inconsistency entirely explained by undefined behaviour?

During a discussion I had with a couple of colleagues the other day I threw together a piece of code in C++ to illustrate a memory access violation. I am currently in the process of slowly returning to C++ after a long spell of almost exclusively…