[fpc-devel] how to get same pthreads code to compile between Linux and FreeBSD
Sven Barth
pascaldragon at googlemail.com
Sun Feb 3 13:28:02 CET 2013
On 03.02.2013 11:51, Graeme Geldenhuys wrote:
> Hi,
>
> I initially posted this in the fpc-pascal list, but I think fpc-devel is
> maybe more appropriate, because the pthreads include files might need
> amendment.
I personally think that the fpc-pascal list was the more approbiate, but
nevertheless: your problem comes down to this code (in principal):
=== code begin ===
program semtest;
type
sem_t_rec = record
end; // from rtl/freebsd/ptypes.inc
sem_t = ^sem_t_rec; // from rtl/freebsd/ptypes.inc
psem_t = ^sem_t; // from packages/pthreads/src/pthrbsd.inc
procedure sem_init(sem: psem_t);
begin
end;
procedure sem_init(var sem: sem_t);
begin
end;
var
s: sem_t;
begin
sem_init(@s);
end.
=== code end ===
Now the problem is the "@s". This returns type "Pointer" and now you
have two pointer types: sem_t and psem_t. Thus the compiler can not
resolve this.
Solution: Typed addresses. Change your call the following way:
=== solution begin ===
begin
{$push}
{$typedaddress on}
sem_init(@s);
{$pop}
end.
=== solution end ===
In this case the return type of "@s" will be "^sem_t" instead of
"Pointer" and then the compiler will find the correct method.
Now one might nevertheless ask the question why the compiler considers
the var variant with an "@s" valid at all? Maybe this is a bug indeed...
Regards,
Sven
More information about the fpc-devel
mailing list