Forum unknown
· Modula-2
#FastFileIO
1 messages in this thread
A pointer is really nothing but an address. Your question brings up the
reason why Modula-2 does not let you normally increment a pointer, because
you run into all sorts of problems (like whether it's a pointer to bytes, to
words, or to longwords). This can be quite dangerous in languages that do
allow you to do that (such as C). To accomplish this in M2, you gotta cast
(i.e. type transfer) to LONGCARD first, then increment that, and then cast
back to pointer. The amount you increment decides how far the pointer was
bumped. For example:
VAR lc : LONGCARD; charptr : POINTER TO CHAR;
intptr : POINTER TO INTEGER;
BEGIN
lc := LONGCARD(charptr);
INC(lc);
charptr := ADDRESS(lc); (* just bumped charptr to next byte
*)
lc := LONGCARD(intptr);
INC(lc,2); (* TSIZE(INTEGER) = 2 *)
intptr := ADDRESS(lc); (* bumped intptr to next integer *)
Hope this helps.
– Steve –