News for hackers. Stuff that matters.
Re:C Minus Minus by distcs on Wednesday October 19, 2022 @07:40AM (#33260673)
I asked this on Ask HN sometime back but did not get a lot of responses. So asking it here because it might be of interest to people reading and commenting on this artile here.

Which programming language other than C is available for most platforms?

It is well known that some C compiler implementation is available for almost every computable platform. I am looking for another programming language that has compiler implementations available on a large number of platforms. It must compile source code into native machine code. It doesn't have to match C in ubiquity. It can be less popular than C. But are there any compilers out there that are available on a large number of platforms?

Re:C Minus Minus by SQueeeeeL on Wednesday October 19, 2022 @07:50AM (#33260759)
This is not a direct answer for compiled languages, but Greenspun's tenth rule feels relevant here:

>Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp

Re:C Minus Minus by naasking on Wednesday October 19, 2022 @07:52AM (#33260777)
> Which programming language other than C is available for most platforms?

Wouldn't any language frontend for gcc count? Last I checked that includes Ada, Fortran, and others.

Re:C Minus Minus by arein3 on Wednesday October 19, 2022 @11:00AM (#33263227)
Are all languages supported by gcc compiled to the same intermediate code?
Re:C Minus Minus by exDM69 on Wednesday October 19, 2022 @11:42AM (#33263824)
Yes, but GCC has several internal representations, Gimple and RTL.
Re:C Minus Minus by Narishma on Wednesday October 19, 2022 @11:17AM (#33263477)
Last time I looked, GCC had pretty poor support for 16-bit x86 compared to older compilers.
Re:C Minus Minus by atan2 on Wednesday October 19, 2022 @07:53AM (#33260791)
Well, not really a systems language (and strongly dependant on C), but Lua is usually a good choice and it runs virtually everywhere.
Re:C Minus Minus by amatria on Wednesday October 19, 2022 @08:06AM (#33260916)
:ICANT: java :ICANT:
Re:C Minus Minus by bryanlarsen on Wednesday October 19, 2022 @08:10AM (#33260956)
Two very different answers for you.

1: Forth. I've seen Forth on things that I didn't even realize were computers. Since an interpreter can run in a few hundred bytes of ROM, that's not too surprising.

2: Rust. Rust can run on 8/16 bit micros, client side web (WASM), and on iOS, along with all of the more conventional and easier targets. Probably the only popular universal language for 2022 targets, although there are Rust competitors like Zig that may falsify that statement.

And in a nice coincidence, both languages are fun.

Re:C Minus Minus by _gerald_ on Wednesday October 19, 2022 @09:26AM (#33261798)
Does anyone know how Zig solves the memory-safety and concurrency questions? I tried Googling it and according to this blog post:

https://mikefsn.github.io/2022/10/18/goodbye-zig.html

it doesn't look like it offers solutions. The only thing I could find in the docs was about concurrency where they say "[concurrency] is an area of active research":

https://ziglang.org/learn/overview/#concurrency-via-async-fu...

Re:C Minus Minus by AndyKelley on Wednesday October 19, 2022 @11:14AM (#33263426)
This guy has been doing "concern trolling" about once a day for a week now: https://gist.github.com/andrewrk/9aed922a6210e57243af8be8d10...

There's plenty of things to criticize about Zig. Just do it honestly instead of pretending that you're "just asking questions".

Re:C Minus Minus by j-krieger on Wednesday October 19, 2022 @08:10AM (#33260960)
> Which programming language other than C is available for most platforms?

There is almost no platform java can't run on. Rust is a bit esoteric, but it can run anywhere you have a working libc.

Re:C Minus Minus by umanwizard on Wednesday October 19, 2022 @08:18AM (#33261021)
> Rust is a bit esoteric, but it can run anywhere you have a working libc.

I don’t think that’s true. Doesn’t Rust only run on platforms that LLVM supports?

Re:C Minus Minus by j-krieger on Wednesday October 19, 2022 @09:27AM (#33261802)
I'm wrong, but you're also incorrect. Turns out, that rust can in theory run anywhere you have a libc, but if the target isn't known to the compiler yet, it's on you to connect libc to the rust STD.
Re:C Minus Minus by umanwizard on Thursday October 20, 2022 @09:14AM (#33274193)
How can rust run somewhere that LLVM doesn't support?
Re:C Minus Minus by FartyMcFarter on Wednesday October 19, 2022 @09:15AM (#33261664)
Java requires a certain amount of memory and CPU power (if nothing else because it's a garbage collected language).

I doubt Java is available on some of the smallest computers C can run on, like many microcontrollers or legacy platforms.

Re:C Minus Minus by haspok on Wednesday October 19, 2022 @09:55AM (#33262180)
There is https://en.wikipedia.org/wiki/Java_Platform,_Micro_Edition

But of course, a 32KB RAM minimum would be too much for some legacy systems. Still, Java is actually far more flexible than most people would think.

(Also, at its heart the JVM is just a Forth-like stack based interpreter, and I would guess that loading and parsing a .class file is more complicated than the interpreter itself!)

Re:C Minus Minus by pjmlp on Wednesday October 19, 2022 @10:42AM (#33262955)
Smart Cards?

Full C is also not available everywhere, specially 8 bit and 16 bit computers where it is mostly a pseudo macro assembler.

Re:C Minus Minus by blueflow on Wednesday October 19, 2022 @08:11AM (#33260966)
If you are looking for a language that is portable across platforms and widespread/long-lived enough to make learning it deep worth it, i think C is unmatched and will probably stay like this for a while.
Re:C Minus Minus by samatman on Wednesday October 19, 2022 @08:16AM (#33261000)
Forth is available for more platforms than C, and like C, it is usually but not always a compiled language. Because Forth always has an interpreter, and a powerful one, it's more obvious that Forth doesn't have to compile to run, but again, true of C as well: https://gitlab.com/zsaleeba/picoc exists, and it isn't the only one.

Edit: an important difference between them is that C implementers take the standard very seriously, while Forth is culturally resistant to standardization, Chuck Moore being on record as having considered it a bad idea, and disliking the resulting ANSI Forth language.

If the goal is to compile "the same code everywhere", well, good luck doing that with C, but with enough #ifdefs it can be done. The Forth approach is to have a personal base layer of words, which one either adapts or implements for a given system, and target the rest of one's code at that dictionary.

Re:C Minus Minus by badsectoracula on Wednesday October 19, 2022 @09:24AM (#33261762)
Free Pascal[0] supports a wide range of platforms and architectures. From the site:

> Free Pascal is a mature, versatile, open source Pascal compiler. It can target many processor architectures: Intel x86 (16 and 32 bit), AMD64/x86-64, PowerPC, PowerPC64, SPARC, SPARC64, ARM, AArch64, MIPS, Motorola 68k, AVR, and the JVM. Supported operating systems include Windows (16/32/64 bit, CE, and native NT), Linux, Mac OS X/iOS/iPhoneSimulator/Darwin, FreeBSD and other BSD flavors, DOS (16 bit, or 32 bit DPMI), OS/2, AIX, Android, Haiku, Nintendo GBA/DS/Wii, AmigaOS, MorphOS, AROS, Atari TOS, and various embedded platforms. Additionally, support for RISC-V (32/64), Xtensa, and Z80 architectures, and for the LLVM compiler infrastructure is available in the development version. Additionally, the Free Pascal team maintains a transpiler for pascal to Javascript called pas2js.

[0] https://www.freepascal.org/

Re:C Minus Minus by Tozen on Wednesday October 19, 2022 @10:53PM (#33270293)
Good post. Too many people act like there is C or C++, then nothing else. As Pascal shows and along with others, there are various options, if one chooses to see them.
Re:C Minus Minus by distcs on Thursday October 20, 2022 @05:19AM (#33272378)
> As Pascal shows and along with others, there are various options

The number of platforms Pascal is available looks impressive! Can you mention some of the others like that? You say there are various options. What are those?

Re:C Minus Minus by Tozen on Friday October 21, 2022 @04:24AM (#33285816)
Ada is up there with Pascal (which there are various dialects aimed specifically at embedding) as an alternative. Some people will take issue, but Java and Go can be viable alternatives as well.

Lots of activity and talk to try to push Rust into being a stronger alternative too. There are also the other newer C alternative languages and languages that compile to C (Nim, Vlang...), that can be directed towards this purpose. Speaking of Vlang, there is now a project for it to compile to Pascal, as one of its backends (in addition to C and WASM).

So... Pascal, Ada, Java, Go (including TinyGo), Rust (future), and others mentioned (future/transpile to C)...

Don't get me wrong, C dominates. But, depending on what is being done, its not the only language that has to be used or it can be written in something else that transpiles to it.

Re:C Minus Minus by pjmlp on Wednesday October 19, 2022 @10:43AM (#33262962)
Besides all other replies, C++.