Prof A Olowofoyeku (The African Chief) wrote:
Mehdi Khaldi wrote:
Hi, Is it possible to use universal pointer like void* in C? I have seen that there is a keyword "univ" with sun compiler. How to do to have universal pointer with gpc?
"Pointer"
Frank Heckenbach wrote:
Adriaan van Os wrote:
(7) Filter out a handful of compiler features that would really assist GPC development on Mac OS X (and porting from CodeWarrior). On this list wil be UNIV parameters, I guess, but this is premature.
No idea what they are ...
Like the Sun compiler, Macintosh Pascal compilers have the UNIV keyword. UNIV is put before the type (after the colon) in parameter lists and says "don't complain if the types of actual parameter and formal parameter don't match, as long as they have the same sizes in bytes".
Please note that this is more restrictive than Delphi's untyped variables (which are not typed and sized at all, and therefore VAR parameters only).
Use of UNIV is not restricted to universal pointers, although in actual practice that is indeed the most common case. With the "Pointer" type in GPC, I found a case that doesn't work.
Consider the following three cases (see the testprogram below for details).
(1) typed pointer passed as value parameter. Works in GPC and Delphi. (2) typed pointer passed as variable parameter. Works in GPC, but not in Delphi. (3) typed pointer in procedural parameter list passed as actual parameter. Works not in GPC and not in Delphi.
All three cases work in Macintosh Pascal compilers (with UNIV attached to the pointer type).
Regards,
Adriaan van Os
---------
program testuniv;
type rec = record a: integer; b: longint end; recptr = ^rec; ord4 = cardinal( 32); var gr : rec; gp : recptr;
{$X+} procedure incptr( var p: {univ} pointer); begin p:= p + 1 end;
procedure writeptr( p: {univ} pointer); begin writeln( 'p = ', ord4( p)) end;
procedure writerec( rp: recptr); begin writeln( 'a = ', rp^.a, ', b = ', rp^.b) end;
procedure writebyptr( pp: {univ} pointer; procedure pwrite( p: {univ} pointer)); begin pwrite( pp) end;
begin gr.a := 123; gr.b := 456; gp := @gr; writerec ( gp); writeptr ( gp); incptr ( gp); writebyptr( gp, writeptr); writebyptr( gp, writerec) { <--- not allowed by GPC compiler } end.