Message-Id: <200002260336.WAA05805@delorie.com> From: "Richard Poole" To: Subject: Compiling a function to raw executable code. Date: Sat, 26 Feb 2000 03:40:38 -0000 X-MSMail-Priority: Normal X-Priority: 3 X-Mailer: Microsoft Internet Mail 4.70.1155 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Is it possible for me to use GCC to compile a function to raw machine code and nothing else (i.e. no run-time engine, no DMPI server etc.)? I am writing a modular audio synthesiser that opens all files ending in a certain extension and copies their contents into allocated memory. These files (otherwise known as devices) should contain raw executable code, and I need the main program to be able to call that code. In the main program there is an array of pointers to the devices that it has loaded into memory, like this... -------- start -------- typedef struct DEVICE_STRUCT { ... void (*code)(unsigned int *,unsigned int *); } DEVICE_STRUCT; struct DEVICE_STRUCT device[1024]; -------- end -------- Some of the functions that will be called are too complicated to write in assembler, so it would be very useful to be able to write them in C, like this... -------- start -------- void half_volume(unsigned int *inports[256],unsigned int *outports[256]) { outports[0]=inports[0]>>1; return; } -------- end -------- Clearly a grossly simplified example of a near useless piece of audio equipement, but hopefully it demonstrates my point. How could I get GCC to compile that function so that the executable it generates contains only the compiled code within that function (i.e. outports[0]=inports[0]>>1; return;) so I can load it into allocated memory and call it? Say device[0].code is pointing to the allocated memory that the code of half_volume has been loaded into. -------- start -------- int inports[256],outports[256]; inports[0]=32768; device[0].code(inports,outports); -------- end -------- At this point, outports[0] should be equal to 16384. Hopefully that helped you understand the problem if you didn't before, otherwise it's probably just confussed everyone, but please mail me if you have any insight into the problem. Many thanks, Richard Poole.