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 observable behavior or not? According to C++ Standard (1.9/6) the observable behavior includes:
- reads and writes to
volatile
data - library I/O functions
Now srand()
and rand()
are likely not I/O functions (although I have no idea whether a given implementation uses some hardware noise source), but they modify program internal state. Do they manipulate volatile
data? I don't know. Calls to printf()
are clearly I/O operations and sequences thereof are identical in both programs.
Do the two programs above have the same observable behavior? How do I know if two given programs have the same observable behavior?