Originally Posted by
Prelude
Because it reeks of undefined behavior.
Reeks? No, I'm fairly certain that it is. Here's what I tried:
Code:
#include <iostream>
#include <ctime>
#include <windows.h>
using std::endl;
using std::cout;
int main()
{
unsigned int *p = new unsigned int;
/*
used just so that I have time to start the
program twice in a second
*/
Sleep(1000);
/*
between incrementing an uninitialized value
and the actual pointer address,
surely something here is unique
*/
cout << ++(*p) << " " << (int)p << " " << time(NULL) << endl;
delete p;
return 0;
}
I'd show you a sample output, except it's pretty meaningless. I think it's enough to say that in the few times I ran the program, it always showed the same values except for the time. When ran in the same second, everything was the same.
edit:
And yes, I'm sorry...that's C++.
Code:
#include <stdio.h>
#include <time.h>
#include <windows.h>
int main(void)
{
unsigned int *p = malloc(sizeof(unsigned int));
Sleep(1000);
printf("%d %d %d\n",++(*p),(int)p,(unsigned long)time(NULL));
fflush(stdin);
free(p);
return 0;
}