News for hackers. Stuff that matters.
Re:Tiny-C Compiler by Laaas on Monday March 13, 2023 @09:57AM (#35135763)
I use tcc for all of my small C "scripts" for doing ioctls, etc. Less bloat, suckless. I imagine most software would be better off using tcc than gcc/clang. Performance isn't that important in most cases.
Re:Tiny-C Compiler by notorandit on Monday March 13, 2023 @10:42AM (#35136324)
I think you are confusing the work of Frabrice Bellard with this very one. The former is a C-language compiler. This once is a compiler for a language called "Tiny C". Understandable confusion, though.
Re:Tiny-C Compiler by doublepg23 on Monday March 13, 2023 @10:03AM (#35135854)
> Performance isn't that important in most cases.

Optimizing for storage space is…better?

Re:Tiny-C Compiler by vidarh on Monday March 13, 2023 @10:08AM (#35135904)
Since they say "scripts", note that tcc supports being invoked in the shebang line. E.g.

    #!/usr/bin/tcc -run
You can do that with gcc/clang too (e.g. #if 0, #endif to wrap a block of shell script to compile the current file and execute the result) but a primary value of tcc is that it compiles fast.

On a more philosophical note, the suckless approach is to optimise for simplicity not storage. It's perfectly valid to disagree with that of course, but if simplicitly of the system as a whole is a consideration gcc and clang doesn't really fit.

Re:Tiny-C Compiler by LukeShu on Monday March 13, 2023 @06:11PM (#35143717)
You can only sort of do that with gcc/clang. The #if 0 trick relies on funny behavior that is in a few common shells. When you try to execve(2) a script without a proper #! shebang, the kernel will return ENOEXEC. Bash will check for ENOEXEC then check a few heuristics to see if it looks like a text file, and if it does, then it will try to run it as a shell script.

This means that your script will work when run from a shell, but won't work when exec()ed from a non-shell program, which is a weird foot-gun.

Re:Tiny-C Compiler by vidarh on Tuesday March 14, 2023 @09:05AM (#35150813)
That makes sense. When I checked the tcc command line I was mildly surprised to see you could do the #if 0 hack at all, so not surprised to hear it has severe limitations.
Re:Tiny-C Compiler by LanternLight83 on Monday March 13, 2023 @10:47AM (#35136410)
Thanks for sharing! I've yet to go through my C phase, but see it on the horizon, and will remember this and the shebang trick.
Re:Tiny-C Compiler by kevin_thibedeau on Monday March 13, 2023 @01:29PM (#35139171)
This is a recommended practice for scripting with Nim if you want a batteries-included language.
Re:Tiny-C Compiler by circuit10 on Monday March 13, 2023 @06:25PM (#35143921)
I feel like a lot of software written in C is written in C for performance reasons. Obviously that’s not always the case and TCC is useful but I wouldn’t say that that most software should use it
Re:Tiny-C Compiler by t-3 on Tuesday March 14, 2023 @03:23AM (#35148326)
C is usually the path of least resistance on *nix, if you're trying to interact with the OS. The docs give you C prototypes and C examples, and the source is mostly C, several standard directories are filled with C code and libraries compiled from C.