ql_freak wrote: Fri Jul 11, 2025 12:00 am
Even if the C68 options to produce reentrant code are working, you can write functions, which you can call from assembler. But you cannot even write the "hello world" program from Kernighan & Ritchie, cause this uses printf(), which is in the standard library which is not reentrant.
Well, the first question would be "why would you ever even
want to write 'Hello World' in a re-entrant way??".
People are mixing up "re-entrant code", "ROMable", and, especially in the QL scene, "re-entrant programs" (in TT-speak "pure programs") all the time - These are three totally different things, however.
Re-entrant code is perfectly possible with C68 - simply don't use global or static variables (and don't use C library routines that do that) and your code will be perfectly re-entrant. Use mt_create() to run various jobs within a single executable on the very same code, no problems whatsoever.
ROMable programs are programs that never modify themselves and have code and non-const data cleanly separated (in the case of a QDOS job, they only ever write to the job's data space and allocated heap memory). You can only do that in C68 when you tell the compiler to not use its standard relocating loader but rather produce position-independent code. Also, don't use statics or globals, as above. Unfortunately, you cannot use the standard startup code and many/most of the libraries - which you wouldn't want to anyways, because of the nature of code you'd want to blow into a ROM (See above: Why would you want to put "HelloWorld" into a ROM?).
"Pure" programs are programs that can be started through the Hotkey System multiple times and can share the same instance of code, but have a private data space - They have basically the same restrictions as ROMable code.
QDOS/SMSQE is built in a way that it comforts programs of all kinds - Even Device drivers or Things don't necessarily need to be re-entrant, at least not when they serve atomic calls. The OS makes sure there is ever only one code path through them at any on time.
"Impure" programs are in no way any "worse" than "Pure" ones. Just different. There is actually not much point to desire only "pure" programs on the QL - You have to invest a large amount of effort if you aim for them in anything but assembly. And, I'd rather have a working, "impure" one, than a non-finished "pure" one.....