[fpc-pascal] Problem translating c code to pascal

Marc Santhoff M.Santhoff at t-online.de
Sat Sep 23 18:51:14 CEST 2006


Am Samstag, den 23.09.2006, 12:39 -0300 schrieb Felipe Monteiro de
Carvalho:
> Hello,
> 
> I'm converting apache 1.3 headers to pascal, and I found something I
> don't know how to convert. It's these lines:
> 
> static const handler_rec hw_handlers[] = {
>      { "hw-app", hw_handle_req },
>      { NULL }
> };
> 
> Where handler_req is declared as:
> 
>   handler_t = function (param1: Prequest_rec): Integer; cdecl;
> 
>   handler_rec = record
>     content_type: PChar;	{ MUST be all lower case }
>     handler: handler_t;
>   end;
> 
> And hw_handle_req is a function of type handler_t
> 
> I don't understand what exactly that constant is. I looks like a
> dynamic array with 2 elements, but the second is NULL. How can a
> structure be NULL ?

Typically such structure arrays are iterated by the part using them.
This way one can add new items simply by writing the name and associated
handler into the code, if needed.

Think of hardware detection, one driver may know different models it
supports. When detection is active it simply iterates over the model
describing struct and checks presence until the item read from the
struct is NULL.

I think, a NIL pointer in pascal will do, although I have no idea what
this is good for in apache:

const
	first_handler_rec = (("hw_app"), (@hw_handle_rec));
type
	Phandler_rec = ^handler_rec
var
	hw_handlers: array of [0..1] Phandler_rec = (
		first_handler_rec,
		NIL
	);

That should be close to the pascal syntax for this construction - not
checked, only typed away.

Maybe you can put the constant value into the array directly, omitting
to have it separated and maybe you can omit the array size (0..1) too,
you'll have to try.

HTH,
Marc





More information about the fpc-pascal mailing list