How to translate C macro

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to translate C macro

Darius Blaszyk
Hi all,

Could someone suggest how to translate the following code to pascal?

#define prev(X) (  *( (void **) (  ((void *) (X)) - 32  ) )  )
.....
prev(ptr) = prev(last);

I tried converting the macro to an inline function but I get the error message: Error: Argument cannot be assigned to.

The following does work but is a bit verbose. So therefore I would prefer a clean solution if possible. I never have used macro's in FPC, are they capable of doing the same as mentioned above?

( ppointer (  (pointer (ptr)) - 32  ) )^ := ( ppointer (  (pointer (last)) - 32  ) )^;

Thanks in advance!

Regards, Darius
 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to translate C macro

Santiago A.
El 02/01/2017 a las 21:57, Darius Blaszyk escribió:

> Hi all,
>
> Could someone suggest how to translate the following code to pascal?
>
> #define prev(X) (  *( (void **) (  ((void *) (X)) - 32  ) )  )
> .....
> prev(ptr) = prev(last);
>
> I tried converting the macro to an inline function but I get the error
> message: Error: Argument cannot be assigned to.
>
> The following does work but is a bit verbose. So therefore I would
> prefer a clean solution if possible. I never have used macro's in FPC,
> are they capable of doing the same as mentioned above?
>
> ( ppointer (  (pointer (ptr)) - 32  ) )^ := ( ppointer (  (pointer
> (last)) - 32  ) )^;
If I have understood right, it could be something like this,

dec(ptr,32);
dec(Last,32);
ptr^:=Last^;

but maybe I have missed some indirection.

You could show a little of code to see what do you intend to do. Change
the 32th backward element of an array of pointers?
 

--
Saludos
Santiago A.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal