Reputation: 2618
I've found an old C source code that I've implemented several years ago, and also its compiled binary executable.
In a comment I wrote that the compilation command was:
gcc -O3 source.c -o executable -lm
So I recompiled it but the new executable is different (in size) from the old one.
In fact if I run the new and the old executable they give me different results: the old executable returns the same result returned years ago, while the new one returns a different result.
My goal would be to be able to recompile the source and obtain the same executable as the old (or at least an executable that produce exactly the same result).
I'm sure that I run the two programs with the same parameters, and that the code does not use threads at all. The only particular thing is that I need random integers, but I use my own function to produce them just in case to be sure that the sequence of random numbers is always the same (and of course I always use the same seed).
unsigned int seed = 0;
void set_srand(unsigned int aseed) {
seed = aseed;
}
int get_rand() {
seed = seed * 0x12345 + 0xABC123;
int j = (seed >> 0x10) & RAND_MAX;
return j;
}
(I thought this was copied from some library).
So what can it be? Maybe the OS where the compilation is done (the original one was under WinXP, now I'm trying under both Win7 and Ubuntu), but I've always only used MinGW. So maybe the version of MinGW? If this is the case, I'm in trouble because I don't remember which version I've used several years ago.
Libraries that I use:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
What I do are only string operations and computation like pow()
, sqrt()
, multiplication and plus/minus, in order to apply an heuristic optimization algorithm to solve approximately an NP-hard problem: the results are both solutions of the problem, but their fitness differs.
Upvotes: 0
Views: 404
Reputation: 16512
The first thing I would check is the size of int. Your code relies on overflow and the size of integers may matter.
Your code seems to imply that int is at least 32 bit (you use 0x0x269EC3) but maybe you are now compiling with int at 64 bit.
I wouldn't worry about executable file, it's very unlikely you get the same size by two different compilers.
Upvotes: 1