How faithful is fgetc, fputc, and gcc compile?

0

I'm interested in how faithfully a program like the following would reproduce itself:

fgetc(sourcefile) to read source file.

fputc(daughterfile) to write a new source file.

gcc to compile the daughter file.

I can run diff/cmp on the two files (the original and the daughter) and I get mixed results. Diff says they are exactly the same, cmp gives a very long list of their differences, but I think that might be because the names are different, and the names are being compiled into the executable.

Of course, these programs should be exactly the same over many, many repetitions, but I'm wondering if anyone can point me to a discussion that might give me an idea how often a procedure like the one outlined above would result in data corruption.

(And FYI in case it matters, I'm interested in any changes, even those which don't directly interfere with the execution of the code. Basically, any changes to the file which I didn't intend.)

levitopher

Posted 2017-08-07T02:23:19.473

Reputation: 121

1"Diff says they are exactly the same, cmp gives a very long list of their differences" -- Exactly what are these results (and post the original program file)? "give me an idea how often a procedure like the one outlined above would result in data corruption" -- Only if the copy program has a bug(s). – sawdust – 2017-08-07T05:10:40.080

2

An answer is provided by https://stackoverflow.com/questions/16479006/can-i-use-fgetc-or-fputc-in-a-binary-file

– sawdust – 2017-08-07T05:28:35.777

^^ So the answer there is "fgetc() and fputc() are 100% accurate, all the time"? I guess I care about "in practice" rather then "in theory", but much more information would be needed about the environment to evaluate "in practice". – levitopher – 2017-08-08T03:11:39.770

"...but much more information would be needed..." -- Yes, like your "program". – sawdust – 2017-08-08T19:42:12.827

No answers