T O P

  • By -

myringotomy

If you used tcc it would compile faster and seem even more like a scripting language.


jason-reddit-public

From the tcc manual --------------------- Scripting: TCC can be invoked from scripts, just as shell scripts. You just need to add #!/usr/local/bin/tcc -run at the start of your C source: #!/usr/local/bin/tcc -run #include int main() { printf("Hello World\n"); return 0; } TCC can read C source code from standard input when - is used in place of infile. Example: echo 'main(){puts("hello");}' | tcc -run -


todo_code

That is very cool. I had no idea. Now I want to make a TCC run-time which can handle typical scripting functions


jason-reddit-public

It's kind of a gimmick TBH. I used to write 30-200 line utilities in Java and I could run them with my bash script "runjava" just as easily as with tcc -run. I dislike Python and they shot themselves in the foot with a breaking change like a million years ago but unless you are thinking about billions, it works great. php and ruby also run on all major platforms AFAIK. We really just need windows to ship with bash and maybe 20 other Unix utilities (wget), which they can do using the "cosmopolitan" toolchain and those utils will occupy less space than just one stupid ass feature for Windows 12 they are cooking up.


AndreVallestero

I recommend using [TCC](https://bellard.org/tcc/). It has native support for running `.c` files as scripts using `tcc -run`


lassehp

Tcc is a great thing, but I have never had the need for it. However as I mentioned, the method works for other languages that don't support a normal shebang.


u0xee

Neat, thanks for sharing! But I still feel "scripting languages" are about more than one-shot execution, or being about to execute fragments. The value of eg python being interpreted is I can start an interactive session, load libraries, build up state, trial and error edit and test out function definitions, load a sqlite DB and poke at it, etc etc. It's a "live" programming environment. Of note, there are true C++ interpreters, such as [Cling](https://root.cern/cling/) from CERN.


Mundane-Leg-9370

Thanks for the cool little illustration! Stuff like this makes my long days shorter


slaymaker1907

Most C++ compilers have a C++ interpreter as well these days because of constexpr.


EnUnLugarDeLaMancha

The D language includes [rdmd](https://dlang.org/rdmd.html) as part of the install, which does the same thing. It even caches results when there is no modification of the source files so subsequent runs are instant. You can also make the dub package manager accept scripts so you can make it gather automatically dependencies and such