Op Fri, 8 Sep 2006, schreef Jonas Maebe:
Show quoted text 11 lines
On 7 sep 2006, at 22:08, Daniël Mantione wrote:
>
> > Or could we perhaps just import back zutil.pas but without the
> > memory functions?
>
> No, there is no reason why you want to use types like Pulong etc.
One reason to do that is to keep code portable between different Pascal
compilers.
C compilers. At least, that is why there was a zutil, in C there is no way (pre C99) to get a 16 bit integer for example, and for things like compression libraries it is highly important to have data types of fixed size.
Therefore such libraries need to define custom data types with a lot of ifdef statements, which happens in the C version, which was translated to Pascal.
For Pascal compilers, we have a very stable situation, i.e. a word is 16 bits unsigned. There is only some disagreement about the size of a pointer.
Lets take an example:
s^.l_buf := puchfArray( @s^.pending_buf^[(1+sizeof(ush))*s^.lit_bufsize] );
... is totally unreadable. What is actually meant here is:
s^.l_buf := Pbyte(s^.pending_buf) + sizeof(word)*s^.lit_bufsize + 1;
Speaking about paszlib portability, there are many endian issues nobody has ever looked at:
{put_short(s, s.bi_buf);}
s.pending_buf^[s.pending] := byte(s.bi_buf and $ff);
inc(s.pending);
s.pending_buf^[s.pending] := byte(word(s.bi_buf) shr 8);;
inc(s.pending);
Show quoted text 8 lines
> in
> Pascal. Use of standard types that every Pascal programmer understands,
> like Pcardinal, makes the code much more readable.
Indexing pointers as arrays is not exactly a typical Pascal way of doing
things either... And whether or not it's more readable mainly depends on
knowing the fact that FPC allows you to do that (and even then it's sometimes
confusing, although not in this particular case).
Sure, I agree here. But the reason to kick zutil was not because there were declarations like "type arrayname = array[0..$ffffffff] of byte", in fact, such types are still in the code. I consider such types perfect Pascal code.
Daniël