Well close
This is closer:
var
s1:array[0..20] of char = 'some character string';
s2:array[0..15] of char absolute s1[5];
begin
writeln(s1);
writeln(s2);
end.
it's more succinct to simply write
and in addition to being more succinct, it also works in a const block whereas "absolute" does not.
Claiming that C knows arrays is a bit of a stretch. It knows pointers and pointer arithmetic. Any pointer (as long as it isn't void) is an array.
Basically anything that can be expressed in K&R C can be expressed in Pascal too.
that might be true. I don't remember K&R C well enough to argue that point BUT, FPC cannot express all that can be expressed in C++.
Also note the original code is unsafe (you can over-index it..) and this Pascal equivalent isn't....
That pascal equivalent is equivalently unsafe. You can set the index in "absolute s1" to way past the boundaries of s1. That said, credit must be given to FPC for issuing a warning about it but, it won't stop you from doing it (which is a good thing.)
Furthermore: that original code declares vars: not const, but const *
there is no way to declare a const * in FPC. i.e, FPC cannot make a difference between a pointer to an constant array of characters and a zero based array of char in memory.
In some situations (very few), C++ has stronger type checking than Pascal. It is normally the opposite.