gcc vs vc++: Calling data as code
sidster
patrick@mail.boxsoft.com
Tue Jul 25 04:05:00 GMT 2000
Greetings,
I think the attached source does what you ask. Seems to work on my
linux box.
% gcc -v
Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
% uname -a
Linux 3eye 2.2.13 #3 Sun Dec 26 02:14:38 PST 1999 i686 unknown
* Robert Feldt (feldt@ce.chalmers.se) [20000724 23:42]:
[...]
> My friend has an application were machine code is manipulated in buffers
> and then called as code. Here's the challenge and my first effort to solve
> it:
>
> Challenge: Implement the functions f1 and f2 below without writing
> them in C code, ie. by having their machine code in a buffer and
> calling it. Since his interest is in the Wintel architecture it does
> not need to work on other machines/architectures.
>
> float f1(float* in) {
> return in[0] + in[1];
> }
>
> float out[2];
>
> void f2(float* in1, float* in2) {
> out[0] = in[0] + in2[0];
> out[1] = in[1] - in1[1];
> }
[...]
Best regards,
patrick
--
We've heard that a million monkeys at a million keyboards could
produce the Complete Works of Shakespeare; now, thanks to the
Internet, we know this is not true.
-Robert Wilensky
More information about the Gcc
mailing list