Unsolved said:
(e-mail address removed) wrote...
Unsolved said:
[...]
I don't care at all how close to the original program it is.
Then what's the purpose of creating "trashy" C source?
I said it doesn't have to be the original C. While I think we could
agree that there are many, many readable C programs that do the same
thing, your question implies otherwise.
No (or at any rate, I don't think so): I'm suggesting
that mechanical dis-compiling is likely to produce one of
the many possible *un*readable C sources for the object code.
But if it's a readable C program, then your question is badly formed.
If the output is readable, consider yourself either lucky
or an excellent reader ... In any case, questions are valid or
invalid on their premises, not on whatever the answer turns out
to have been.
Nonetheless: C is more portable than ASM, last time I looked.
It depends rather strongly on the C: you have but to lurk
on this newsgroup for a few days to see enough examples of
wildly non-portable C as you can stomach. Here's a plausible
example: somewhere in the object code you find instructions
that load a `double' register from one location and store
it to another. Your dis-compiler may well generate
*(double*)p = *(double*)q;
.... which accurately reflects the object code. Portable?
By no means! What was *really* going on was
struct st { short s; int i; };
struct st x = { 42, 42 };
/* here come the instructions in question: */
struct st y = x;
.... where the compiler decided to copy an eight-byte struct
by copying an eight-byte `double'. How portable is this?
Not very! The compiler has taken advantage of its own non-
portable knowledge in generating the code, as it is permitted
to do. Is the idea that sizeof(struct st) == sizeof(double)
portable? No, it is not. How about alignment: Is there any
guarantee that "alignof(struct st)" >= "alignof(double)"?
No, there is not. How about preservation of representation:
Is there any guarantee that loading something that might look
like a signalling NaN into a `double' register will preserve
its bit pattern for the subsequent store? No, there is not.
If you hope to dis-compile on machine A and re-compile
on machine B and get working code, you may well hope and your
hope may be rewarded, at least some of the time. But you would
be well-advised not to expect much ...