Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-03

pointers under linux

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Shifted Soul

Hello
I get for you some troubles.
Lately I developped a unit which function perfectly under go32 and not under linux. But I didn't use any specific instruction for a given platform.
So I debugged it under linux, and I found where the problem. But why it works under go32 and not under linux.
I give you a sample program which don't work under linux :

{$MODE OBJFPC}
{$H+}
type
  t = ^trec;
  trec = record
    s : string;
    n : t;
  end;
var
  t1 : t;
begin
  new(t1);
  t1^.s := 'hello';
  t1^.n := Nil;
  new(t1^.n);
  t1^.n^.s := 'Hello2';
end.

It will give me RT Error 216 (in the unit, where I use classes, it is Access Violation exception).
gdb told me that it stops at the instruction
_SYSLINUX$$_INITIALIZE$POINTER$POINTER
The problem araises only in these conditions :
+ $H+ enabled
+ chained list
+ initialize the next item by nil (t1^.n := Nil;)
+ create it by new (new(t1^.n);)
it stops then.
I have the solution for the problem :
create the next item seperately and link it :

new(p);
t1^.n := p;

but I want to know why we can't use the first way ? Sorry for the problem.

NB : I use fpc 1.0.4 under linux RPM version, I will use the next version when i complete downloading it (I have a modem with 4kB/s)

Unknown author
to Shifted Soul

Date sent: Fri, 15 Mar 2002 09:35:50 +0100
From: Shifted Soul
To: fpc-pascal
Subject: [fpc-pascal]pointers under linux
Send reply to:

DON't use $H+

Show quoted text 50 lines
Hello I get for you some troubles. Lately I developped a unit which function perfectly under go32 and not under linux. But I didn't use any specific instruction for a given platform. So I debugged it under linux, and I found where the problem. But why it works under go32 and not under linux. I give you a sample program which don't work under linux : {$MODE OBJFPC} {$H+} type t = ^trec; trec = record s : string; n : t; end; var t1 : t; begin new(t1); t1^.s := 'hello'; t1^.n := Nil; new(t1^.n); t1^.n^.s := 'Hello2'; end. It will give me RT Error 216 (in the unit, where I use classes, it is Access Violation exception). gdb told me that it stops at the instruction _SYSLINUX$$_INITIALIZE$POINTER$POINTER The problem araises only in these conditions : + $H+ enabled + chained list + initialize the next item by nil (t1^.n := Nil;) + create it by new (new(t1^.n);) it stops then. I have the solution for the problem : create the next item seperately and link it : new(p); t1^.n := p; but I want to know why we can't use the first way ? Sorry for the problem. NB : I use fpc 1.0.4 under linux RPM version, I will use the next version when i complete downloading it (I have a modem with 4kB/s) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Lionel Drevon
Adeli http://www.adeli.fr
618 Av. Gal de Gaulle Tel 04 78 66 11 85
69760 Limonest Fax 04 78 66 04 33

Peter Vreman
DON't use $H+

This doesn't solve the problem. He should check the 1.0.5 or 1.1 development release first. There are some fixes regarding the initialization of records

Show quoted text 44 lines
> Hello > I get for you some troubles. > Lately I developped a unit which function perfectly under go32 and not > under linux. But I didn't use any specific instruction for a given > platform. So I debugged it under linux, and I found where the problem. > But why it works under go32 and not under linux. I give you a sample > program which don't work under linux : > > {$MODE OBJFPC} > {$H+} > type > t = ^trec; > trec = record > s : string; > n : t; > end; > > var > t1 : t; > > begin > new(t1); > t1^.s := 'hello'; > t1^.n := Nil; > new(t1^.n); > t1^.n^.s := 'Hello2'; > end. > > It will give me RT Error 216 (in the unit, where I use classes, it is > Access Violation exception). gdb told me that it stops at the > instruction _SYSLINUX$$_INITIALIZE$POINTER$POINTER The problem araises > only in these conditions : + $H+ enabled + chained list + initialize > the next item by nil (t1^.n := Nil;) + create it by new (new(t1^.n);) > it stops then. I have the solution for the problem : create the next > item seperately and link it : > > new(p); > t1^.n := p; > > but I want to know why we can't use the first way ? > Sorry for the problem. > > NB : I use fpc 1.0.4 under linux RPM version, I will use the next > version when i complete downloading it (I have a modem with 4kB/s)
Unknown author
to Shifted Soul: Why ??

Date sent: Mon, 18 Mar 2002 08:07:24 +0100
From: Shifted Soul
To:
Subject: Re: [fpc-pascal]pointers under linux Send reply to:

>DON't use $H+ Why ??

because it crash !

no currently H+ is for Longstring !
it's very strange if you do

new(t2);
t2^.s:='Hello2'#0;
t1^.n:=t2;
writeln('N=',ofs(t1^.n));
it works !
Show quoted text 6 lines
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Lionel Drevon
Adeli http://www.adeli.fr
618 Av. Gal de Gaulle Tel 04 78 66 11 85
69760 Limonest Fax 04 78 66 04 33

Shifted Soul
to Unknown author
Show quoted text 5 lines
new(t2); t2^.s:='Hello2'#0; t1^.n:=t2; writeln('N=',ofs(t1^.n)); it works !

I know it works (I use it now). But the main is to know why it doesn't work in this case :

t1^.n := nil
new(t1^.n);

??