在浏览器中运行C [英] Running C in A Browser

查看:81
本文介绍了在浏览器中运行C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天的时间研究这个看似简单的问题:是否完全可以在浏览器中运行C代码?基本上,我在Appengine中设置了一个站点,该站点需要运行(一组(受信任的)用户)提供的一些C代码并运行它,并将代码输出返回给用户。我从这里有两个选择:我要么需要在浏览器中完全运行代码,要么找到使Python在无需任何系统调用的情况下运行C代码的方法。

I've spent days of research over the seemingly simple question: is it possible to run C code in a browser at all? Basically, I have a site set up in Appengine that needs to run some C code supplied by (a group of trusted) users and run it, and return the output of the code back to the user. I have two options from here: I either need to completely run the code in the browser, or find some way to have Python run this C code without any system calls.

我对问题的回答不一。我已经看过诸如Emscripten之类的解决方案,但这是行不通的,因为我需要在浏览器中生成LLVM代码(我无法在AppEngine中运行编译器。)我尝试了各种技术,包括从codepad.org的输出页面上抓取,但是我将产生的输出太高了,以至于我无法使用codepad.org之类的服务,因为它们会修剪输出(我的输出将是〜20,000行,每行约60个字符,并且会被修剪由于超时而使用键盘输入)。我的最后一招是制造自己的服务器来满足我Appengine网站的请求,但这似乎有些极端。

I've seen mixed responses to my question. I've seen solutions like Emscripten, but that doesn't work because I need the LLVM code to be produced in the browser (I cannot run compilers in AppEngine.) I've tried various techniques, including scraping from the output page on codepad.org, but the output I will produce is so high that I cannot use services like codepad.org because they trim the output (my output will be ~20,000 lines of about 60 characters each, which is trimmed by codepad due to a timeout). My last resort is to make my own server that can serve my requests from my Appengine site, but that seems a little extreme.

我的用户提供的代码将非常有用。简单的C。它们的代码没有I / O或系统操作。不幸的是,我可能不能简单地在他们的代码中使用查找/替换操作将其转换为Javascript,因为他们可能使用多维数组甚至类的结构。

The code supplied by my users will be very simple C. There are no I/O or system operations called by their code. Unfortunately, I probably cannot simply use a find/replace operation in their code to translate it to Javascript, because they may use structures like multidimensional arrays or maybe even classes.

I最好将我的用户限制在一个跨平台浏览器上,例如Chrome或Firefox。谁能帮助我找到这个问题的解决方案?我已经困惑了好几天。

I'm fine with limiting my users to one cross-platform browser, e.g. Chrome or Firefox. Can anyone help me find a solution to this question? I've been baffled for days.

推荐答案

旧问题,但是对于那些在2018年登陆这里的人来说,值得一看网络汇编。

Old question but for those that land in here in 2018 it would be worth looking at Web Assembly.

这篇关于在浏览器中运行C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆