News for hackers. Stuff that matters.
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by BadThink6655321 on Monday February 03, 2020 @07:21AM (#22223523)
Of all the nails that could be used to seal Pascal’s coffin, the one I use is that I can’t write ‘writeln’ in Pascal. Other than that, it was great in it’s time (mid 70’s for me).
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by pjmlp on Monday February 03, 2020 @09:03AM (#22224155)
How do you write malloc() and exit() in C?

You don't, it has to be in Assembly or calling underlying OS APIs.

So also a nail in C's coffin.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by danmg on Monday February 03, 2020 @11:14AM (#22225474)
malloc: Have a big static block of uint8_t and return pointers from it.

exit: longjmp.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by pjmlp on Monday February 03, 2020 @03:04PM (#22228360)
Funny, malloc() implemented that way is UB and doesn't work in all cases, specially when passing pointers around dynamic loaded libraries or threads.

So exit() gets to call longjmp() which definitely can only be done in Assembly, back to step 1.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by danmg on Tuesday February 04, 2020 @10:33AM (#22236669)
Isn't this how malloc was done on classic MacOS?
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by pjmlp on Tuesday February 04, 2020 @02:14PM (#22239722)
Classic MacOS was written in a mix of Assembly and Apple Pascal.

C was a guest language via MPW, and plugged into those APIs.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by nybble41 on Monday February 03, 2020 @12:46PM (#22226706)
> malloc: Have a big static block of uint8_t and return pointers from it.

According to C99 section 6.5 paragraphs 6-7 that would be undefined behavior. The declared type of the object is uint8_t and you're accessing it through an lvalue expression which is not compatible with uint8_t. (You can access any object through a character-type lvalue, but the reverse is not true.) The malloc() function is required to return memory which is disjoint from any other object—that includes your uint8_t array.

Besides aliasing concerns, your character array may not be properly aligned for whatever type is being stored there and there is no way within the C99 standard to determine the alignment of the array or the required alignment for the stored type.

> exit: longjmp.

That might work, in a single-threaded program, if you longjmp() back to main() and return. There's no telling what might happen if you did that from another thread, of course, but then C99 doesn't really cover threads.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by danmg on Tuesday February 04, 2020 @10:34AM (#22236688)
Put the block in a struct and use allignment keywords.
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by nybble41 on Tuesday February 04, 2020 @10:54AM (#22236979)
If you're lucky enough to be using C11 or C18, sure. There are no alignment keywords in C99. However, that still leaves the aliasing issue, and the fact that objects allocated with malloc() are defined not to overlap with any other object.
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by danmg on Tuesday February 04, 2020 @11:08AM (#22237169)
well you also need another static block for the allocation bitmap or whatever structure you're going to use. How would the pointers that you're generated be aliased if they're unique according to your free map.
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by nybble41 on Tuesday February 04, 2020 @06:11PM (#22242156)
They're aliased with the array that you allocated them from. The compiler is free to assume that elements in an array with a declared type of uint8_t won't be accessed via any other type of lvalue (other than another character type). Doing so is undefined behavior, which means there are no guarantees about how any part of the program behaves before or after such an access. In many cases you can get away with it, of course, but a strictly conforming C program can't rely on that.
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by Akira1364 on Monday February 03, 2020 @09:23AM (#22224320)
You use "array of const" to write the equivalent of a regular C variadic function in modern Pascal implementations such as Delphi and Free Pascal:

https://www.freepascal.org/docs-html/ref/refsu69.html

That said, as far as at least Free Pascal goes, there isn't actually even a specific function called `writeln` with a real body that you can go and look at somewhere.

It's a magic language-level intrinsic that gets broken down into calls to various other intrinsics by the compiler based on what's passed to it.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by clouddrover on Monday February 03, 2020 @07:57AM (#22223705)
> I can’t write ‘writeln’ in Pascal

Let's not talk about Pascal from over 40 years ago, let's talk about today's Pascal. Why can't you write "writeln" in today's Pascal?

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by ken on Monday February 03, 2020 @08:10AM (#22223794)
According to Rosetta Code [1], “Standard Pascal does not allow variadic functions” — though specific implementations have proprietary extensions which allow this.

[1]: https://rosettacode.org/wiki/Variadic_function#Pascal

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by unnouinceput on Monday February 03, 2020 @08:22AM (#22223893)
None uses that "standard" when writing stuff in Pascal. Real world uses either Delphi or Lazarus+FreePascal. Both of them have Writeln and variadic functions
Re:Why Pascal Is Not My Favorite Programming Language (1981)... by e12e on Monday February 03, 2020 @08:32AM (#22223963)
Note, I think the point wasn't that Pascal didn't have writeln, rather that you couldn't write (implement) writeln in Pascal (presumably due to missing variadic functions).

So having writeln isn't really the issue, the issue is that writeln is magic/a built-in.

Is free pascal self hosted?

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by Akira1364 on Tuesday February 04, 2020 @10:30AM (#22236636)
You could write something along the lines of `writeln` using `array of const` with today's Free Pascal. It's still strictly better that it's actually implemented as a built-in for various reasons, though.

Also, yes, Free Pascal is entirely self-hosted from the bottom up, making use of inline assembly blocks in some places where it's necessary. It is to Pascal what GCC is to C and C++, basically (which is to say, it has no real dependencies on toolchains other than itself).

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by clouddrover on Monday February 03, 2020 @08:40AM (#22224015)
> Is free pascal self hosted?

Yes.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by clouddrover on Monday February 03, 2020 @08:21AM (#22223890)
Which compiler are you going to use for "standard pascal"? The Pascal compilers you're going to use in practice are either Free Pascal or Delphi. They are what Pascal is today:

https://rosettacode.org/wiki/Variadic_function#Free_Pascal

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by SideburnsOfDoom on Monday February 03, 2020 @07:32AM (#22223563)
Things such as "implement the 'writeln' function" fall under the umbrella of "operating system interop" or "Foreign function interface", don't they?

Any general-purpose programming language, pascal or not, will eventually have that. But it might not be in a general language standard.

Re:Why Pascal Is Not My Favorite Programming Language (1981)... by ken on Monday February 03, 2020 @08:05AM (#22223765)
I think the point is that it’s not so rare that one might run into this type of situation. The article even mentions one.

> It is unfortunate that there is no way to make this convenience available to routines in general.