Sign in Join

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

Mailing lists / fpc-devel / 2004-01

Pchar issue on Win32 with 1.9.2

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Skovrup, Morten Juel

I couldn't get in contact with the bug-report system, but the following code behaves incorrectly (compiled using -Sd):

program TestConsole;
var
  AStr,BStr : string;
procedure WriteStr(p1,p2 : PChar);
begin
  WriteLn(p1,p2);
end;
begin
  AStr := 'Hel';
  BStr := 'Hi';
  //The following outputs 'Hello Hello'
  WriteStr(PChar(AStr+'lo '),PChar(BStr+'Hi'));
  //The following outputs 'Hello Hi Hi'
  WriteStr('Hello',' Hi Hi');
  ReadLn;
end.

Regards
Morten

Reply by email

Michael Van Canneyt
to Skovrup, Morten Juel
Morten Juel wrote
I couldn't get in contact with the bug-report system, but the following code behaves incorrectly (compiled using -Sd):

No, it is correct.
The result of a PChar() typecast on an expression is not defined outside the expression. This is correct behaviour - maybe unexpected. You must explicitly assign the expression result to a string, and typecase that.

This is documented behaviour!

Michael.

Show quoted text 28 lines
program TestConsole; var AStr,BStr : string; procedure WriteStr(p1,p2 : PChar); begin WriteLn(p1,p2); end; begin AStr := 'Hel'; BStr := 'Hi'; //The following outputs 'Hello Hello' WriteStr(PChar(AStr+'lo '),PChar(BStr+'Hi')); //The following outputs 'Hello Hi Hi' WriteStr('Hello',' Hi Hi'); ReadLn; end. Regards Morten _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Skovrup, Morten Juel

OK Thanks!

I didn't find the exact place in the documentation, but this is a change in behaviour right? It worked in earlier versions of FPC and it works in Delphi...

Regards
Morten

Earlier message 53 lines
-----Original Message----- From: On Behalf Of Michael Van Canneyt Sent: 16. januar 2004 14:29 To: Subject: Re: [fpc-devel]Pchar issue on Win32 with 1.9.2 On Fri, 16 Jan 2004, Skovrup, Morten Juel wrote: > I couldn't get in contact with the bug-report system, but the > following code behaves incorrectly (compiled using -Sd): No, it is correct. The result of a PChar() typecast on an expression is not defined outside the expression. This is correct behaviour - maybe unexpected. You must explicitly assign the expression result to a string, and typecase that. This is documented behaviour! Michael. > > program TestConsole; > > var > AStr,BStr : string; > > procedure WriteStr(p1,p2 : PChar); > begin > WriteLn(p1,p2); > end; > > begin > AStr := 'Hel'; > BStr := 'Hi'; > //The following outputs 'Hello Hello' > WriteStr(PChar(AStr+'lo '),PChar(BStr+'Hi')); > //The following outputs 'Hello Hi Hi' > WriteStr('Hello',' Hi Hi'); > ReadLn; > end. > > Regards > Morten > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel >

Reply by email

Peter Vreman
to Skovrup, Morten Juel
Show quoted text 5 lines
OK Thanks! I didn't find the exact place in the documentation, but this is a change in behaviour right? It worked in earlier versions of FPC and it works in Delphi...

No problem here:

C:\Down>pp11 p -Sd
Free Pascal Compiler version 1.9.3 [2004/01/16] for i386 Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling p.pp
Linking p.exe
18 Lines compiled, 0.2 sec

C:\Down>p
Hello HiHi
Hello Hi Hi

C:\Down>

Reply by email

Michael Van Canneyt
to Skovrup, Morten Juel: OK Thanks! I didn't find the exact place in the documentation, but this is a change in…
Morten Juel wrote
OK Thanks! I didn't find the exact place in the documentation, but this is a change in behaviour right?

No, it was always like that.

It worked in earlier versions of FPC and it works in Delphi...

This is pure coincidence. The change in the register allocator just exposes a bug in your code. Delphi documentation also warns against this...

Michael.

Show quoted text 65 lines
Regards Morten -----Original Message----- From: On Behalf Of Michael Van Canneyt Sent: 16. januar 2004 14:29 To: Subject: Re: [fpc-devel]Pchar issue on Win32 with 1.9.2 On Fri, 16 Jan 2004, Skovrup, Morten Juel wrote: > I couldn't get in contact with the bug-report system, but the > following code behaves incorrectly (compiled using -Sd): No, it is correct. The result of a PChar() typecast on an expression is not defined outside the expression. This is correct behaviour - maybe unexpected. You must explicitly assign the expression result to a string, and typecase that. This is documented behaviour! Michael. > > program TestConsole; > > var > AStr,BStr : string; > > procedure WriteStr(p1,p2 : PChar); > begin > WriteLn(p1,p2); > end; > > begin > AStr := 'Hel'; > BStr := 'Hi'; > //The following outputs 'Hello Hello' > WriteStr(PChar(AStr+'lo '),PChar(BStr+'Hi')); > //The following outputs 'Hello Hi Hi' > WriteStr('Hello',' Hi Hi'); > ReadLn; > end. > > Regards > Morten > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Yakov Sudeikin
to Peter Vreman: No problem here: C:\Down>pp11 p -Sd Free Pascal Compiler version 1.9.3 [2004/01/16] for…

Hi guys,

this is two years as I test FPC on my project. Every now and then it does not work. I submit reports, they are fixed, but later on they are here again. I intensively use default parameters, open and dynamic arrays, overloaded functions. They all work, but when used a lot, and especially used together (Say dynarray as a result of an overloaded function, or open array with a default value) -- compiler cannot handle it.

I might be wrong but I guess it is just because nobody esle is using those features so extensively as I do. And these features luck attention of developers. Let's take it seriously and once complete them! Waiting for two years and to see little of progress is no good!

Here is another report. I believe it was working before! Now again with 1.9.2 it is here.

type
 strs = array of string;
function list(b: string = ''): strs;
begin
end;
begin
 list;
end.
bug3.pas(9,2) Fatal: Internal error 200212141

See, I have a project 20000 lines long, with dynarrays, openarrays, defaults and overloads used just in every second line (and that's why it is only 20K lines, not 100K) and I believe that this project is a great test for the compiler! If you guys decide to help me to compile it and get it working as good as it works when compiled with delphi/kylix (console app with only system unit used) -- you will get these four new features really stable!

Thanks,
Yakov Sudeikin

Reply by email

Peter Vreman
to Yakov Sudeikin
you wrote 16 lines
Hi guys, this is two years as I test FPC on my project. Every now and then it does not work. I submit reports, they are fixed, but later on they are here again. I intensively use default parameters, open and dynamic arrays, overloaded functions. They all work, but when used a lot, and especially used together (Say dynarray as a result of an overloaded function, or open array with a default value) -- compiler cannot handle it. I might be wrong but I guess it is just because nobody esle is using those features so extensively as I do. And these features luck attention of developers. Let's take it seriously and once complete them! Waiting for two years and to see little of progress is no good! Here is another report. I believe it was working before! Now again with 1.9.2 it is here.

Dynamic arrays and default parameters are new features and only available in 2 public beta's so you can't expect that they are completly bug free as they don't have enough testing in the field yet. We are dependent on the public to test these features, the compiler itself does not use it.

Also 1.9.x is still not feature frozen. And this bug was introduced as side effect by a new feature register calling and only happends when the result of the function is returned using a hidden parameter. It is impossible for us to see that kind of issues and have them covered in test cases. They only way we find them is when ppl use the features and report bugs. The bug report will then be added to the regression tests.

And btw. the bug was already fixed before you wrote this mail. It is better to follow the daily snapshots when you use new features.

Peter

Reply by email

Yakov Sudeikin
to Peter Vreman

Hi,

What happened with "closedir", "opendir" "Dirent" things in FreeBSD RTL? in 1.1 I used just to add "uses unix;" and the functions were here, now I just cannot find them in the 1.9.2 idea where are they now?

Thank you,
Yakov

Reply by email

Marco van de Voort
to Yakov Sudeikin
What happened with "closedir", "opendir" "Dirent" things in FreeBSD RTL? in 1.1 I used just to add "uses unix;" and the functions were here, now I just cannot find them in the 1.9.2 idea where are they now?

fpopendir, fpclosedir and dirent in baseunix

Reply by email