Some C compilers. consistently reproduce precisely the same output when fed equivalent input. The Gcc of the 2005-12 Mac OS X 10.4.3 often works this way, as do many of the C compilers that target embedded systems.
With a compiler of that kind, you can usefully compare the result of one compilation with the next. For example, you can show that you didn't accidentally introduce a substantive change, while you were reflowing your source code to move its right margin for publication.
However, the Gcc of MinGw can't be used this way, unless you patch it. Instead, by design and by default, this Gcc adds the __DATE__ __TIME__ into your source code, before translating that combination to produce its output.
You can see this easily. Try sleeping one second between compiling and recompiling, and then you will see inconsistent output in such places as:
_IMAGE_DOS_HEADER->_IMAGE_NT_HEADERS->FileHeader.TimeDateStamp _IMAGE_DOS_HEADER->_IMAGE_NT_HEADERS->OptionalHeader.CheckSum
Those are fields of the "Win32 Portable Executable File Format", declared in Windows.h and Winnt.h.
_IMAGE_DOS_HEADER begins the file.
_IMAGE_DOS_HEADER->e_magic should be IMAGE_DOS_SIGNATURE ("MZ").
_IMAGE_DOS_HEADER->e_lfanew is the byte offset of the _IMAGE_NT_HEADERS from the _IMAGE_DOS_HEADER.
_IMAGE_DOS_HEADER->_IMAGE_NT_HEADERS->Signature should be IMAGE_NT_SIGNATURE ("PE").
Microsoft hasn't prominently documented the OptionalHeader.CheckSum algorithm. A guess that often works is to add the file length in bytes to the carries-included sum of whole shorts found in the file, discarding the content but not the count of the leftover byte when the file length is odd:
unsigned short *steps = ...;
int digest = 0;
unsigned short *here = steps;
while ((here + 1) <= eof) { digest += *here++; if (0xFFFF < digest) { ++digest; digest &= 0xFFFF; } }
digest += (((char *) eof) - ((char *) steps));
If all you want to do is to compare successive outputs, you can of course just erase the TimeDateStamp and CheckSum fields that change, without bothering to write meaningful consistent data there. People say rebuilding MinGw Gcc in Windows uses this workaround, so there may be tools in MinGw or MSys that help you do this.
The claims of this page are nothing more than possibly false, quickly gathered, first impressions.
Reality may actually be very different. Hopefully someday we can find an option to turn off this rudely helpful behaviour, somewhere in the Info Gcc.


