There is no package that can just be added to a blog so people can try C online and see the results.
You could provide a link to gcc or another compiler so your readers can try it themselves.
If you were really serious, a CGI script could be created on the server side which:
- Runs in a sandbox (this is critical to get right and is potentially dangerous if done incorrectly)
- Compiles the source code
- Runs the compiled code
- Returns the results
Sorry that I can't give you an easy answer, but there it is.
Answer from teambob on Stack OverflowGCC compiler online version for my website - Stack Overflow
gcc - Virtual Instance of a C compiler on client browser - Stack Overflow
Can anyone recommend an online C compiler that allows #include "myheader.h"?
Is it really that bad to use an online C compiler?
Is the Online C Compiler free to use?
Can I use the Online C Compiler offline?
Is the Online C Compiler suitable for advanced programmers?
Videos
Originally I userstood your question to be targeting the native platform on which the browser is running:
Consider that Browsers may be running on many different platforms, operatinng systems and processor architectures. Compiling C in the way you describe might be technically doable, but practically infeasible.
I was basing "practically infeasible" on the difficulty of supporting the plethora of widely used browser platforms.
Now I understand that you are thinking more on the lines of targeting a virtual environment. I'll amend practically infeasible to "a large amount of work".
If I understand your intent it is to run a C compiler which emits, shall we say, x86 compiled code and executes it. So to do that we need an emulation of the x86 environment in, say, JavaScript. What's more I think your intent is that the conmpiler itself execute in this environment, so that you can re-use gcc. So you'll need to emulate a file-system too. It's "obvious" that this could be done, but it really is a lot of work. Is it really worth it?
Competition code is small (I guess) even with lots of programmers the number of simultaneous compiles can't be so huge with a decent queued request system, a touch of Ajax, and a bit of back-end scaling how costly is it to support the expected population? What's the ratio of developers to back end systems?
Anyway, if I were to address this problem I'd go for taking the code for an opensource browser and melding in the gcc code. Produce a compiler/browser hybrid. Give that to the developers and tell them "Use this and get zippy compilation speeds, or use your own browser and join the queue."
You're not going to use GCC as it is written for this. AT BEST, you could accomplish something simalar if you had a compiler written in Java that targeted the JVM and could be ran as an applet. I don't know what it would take to get something like this working but, I suspect it would take a bit work to get it up and going. As far as I know nothing currently exist that does this.