Sign in Join

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

Mailing lists / fpc-pascal / 2002-07

FPE error inside compiler

11 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

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

Stefan Ziegenbalg

Hi,

what does "FPE error inside compiler" mean. It occurs under certain circumstances (if I use single's instead of double's, ...).

Does it mean "Floating point exception error ..."?

Here is a piece of code:

...
if SImg_DebugLevel>0 then dec(SImg_DebugLevel);
end;
procedure SImg_New(cc:CSImg_Config; var ri:TSImg_RDImage;
     fmt:TSImg_RawFormat; nx,ny,nc:longint); { create new image }
begin
ri.nx:=nx; ri.ny:=ny; ri.nc:=nc;
ri.xc:=0; ri.yc:=0;
...

The error occurs between "end;" and "procedure ...". If I insert an error before "procedure..." FPC shows this error and compiles to end (unless the error is fatal). If there is no error or an error after "end;" the compiler aborts with the message above.

Please contact me, if you want the full source (it is a little bit large).

Regards Stefan

----------------------------------------------

http://www.sziegenbalg.de
http://www.simage.org

A.J. Venter
to Jonas Maebe

Ok,
I am getting more annoyed by the day with these PChars. Half the packages use them, and I they don't seem to have any REAL still have the 256 character limit (as I found out today when a program suddenly broke) they cannot be easilly typecast to strings and back and who know how many other idiotics in there.

Why larry why ?

I use ansistrings for almost everything, but here I am creating a mysql backed CGI when suddenly stuff starts mysteriously breaking, and I discover (after nearly and hour of hunting through over 2000 lines of code) that even though my ansistring CGI input works fine, any remotely big textarea becomes to big to fit into a pchar, which is what I need to typecast (and whoever heard of needing 4 different statements to typecase one string type to another ?) my inputs to in order to do a mysql_query.

Ok, so besides the rant, can somebody please explain to me just what it is that makes pchars popular, or even allows their continued existence ? Is there something I missed ?
Or is just a case of C having pathetic string handling and pchar being a pathetic string handler for pascal because it is designed ot be C compatible ?

/me bangs head against table repeatedly.

Ciao
A.J.

Jonas Maebe wrote 12 lines
On Wed, 17 Jul 2002, Jilani Khaldi wrote: > does FPC have the Delphi StrToFloat function? Yes, it's part of the sysutils unit. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Martyn Ranyard
to A.J. Venter: I am getting more annoyed by the day with these PChars. Half the packages use them, and I…
A.J. Venter wrote 6 lines
Ok, I am getting more annoyed by the day with these PChars. Half the packages use them, and I they don't seem to have any REAL still have the 256 character limit (as I found out today when a program suddenly broke) they cannot be easilly typecast to strings and back and who know how many other idiotics in there.

(bear in mind I am talking from a TP/BP/Delphi standpoint - any differences are unlikely in this respect, but if there are then I expect someone will correct me)

This doesn't seem right - a PChar is just a pointer to a character, where the string follows on flat-form in memory, with a #0 at the end. Is this what's going wrong? Have you forgotton to add the null character at the end?

Show quoted text 7 lines
I use ansistrings for almost everything, but here I am creating a mysql backed CGI when suddenly stuff starts mysteriously breaking, and I discover (after nearly and hour of hunting through over 2000 lines of code) that even though my ansistring CGI input works fine, any remotely big textarea becomes to big to fit into a pchar, which is what I need to typecast (and whoever heard of needing 4 different statements to typecase one string type to another ?) my inputs to in order to do a mysql_query.

Are you sure it's not being typecast outside of your code and when passed as a pchar?

Ok, so besides the rant, can somebody please explain to me just what it is that makes pchars popular, or even allows their continued existence ? Is there something I missed ?

In the windows world, where C rules supreme, strings are simply placed into char arrays with a null character at the end. That's why they're so popular. I would have thought that the code behind ansistrings are pchars, but I may be wrong.

Or is just a case of C having pathetic string handling and pchar being a pathetic string handler for pascal because it is designed ot be C compatible ?

Yes, as most languages/APIs interoperate with C, they expect certain things as c strings, which pascals pchars are completely compatible with. Like I say, I am unaware of any length limit - there certainly isn't one in the Borland compilers.

/me bangs head against table repeatedly. Ciao A.J.

Martyn Ranyard

Free Software Advocate
email:
jabber:
msn:

Nikolai Zhubr
to Martyn Ranyard

Hi,
Thursday, 18 July, 2002, 23:16:12, Martyn Ranyard wrote: [...]

This doesn't seem right - a PChar is just a pointer to a character, where the

Consider the following example (for Delphi):

var
  st: string[10] = 'Hello';
begin
  writeln(PChar(@st[1]) + ' !!!');
end.

The output is:
Hello !!!
Does this mean we can add strings to pointers? No. Consider the next one:

type
  HonestPChar = ^Char;
var
  st: string[10] = 'Hello';
begin
  writeln(HonestPChar(@st[1]) + ' !!!');
end.

Delphi says:
Error: Incompatible types: 'string' and 'HonestPChar'

BTW, this doesn't fit well enough in my head ;) yet. Its like C belch or something... I'm afraid of pchars.

Sorry don't know how FPC takes this (yet).

string follows on flat-form in memory, with a #0 at the end. Is this what's going wrong? Have you forgotton to add the null character at the end?

[...]

I would have thought that the code behind ansistrings are pchars, but I may be wrong.

Delphi's rtl handles strings' operations independently of pchars whenever possible, iirc. (That is, when not mixed, etc.)

Best regards, Nikolai Zhubr
Giovanni Premuda
to Nikolai Zhubr

----- Original Message -----
From: "Nikolai Zhubr"

Thursday, 18 July, 2002, 23:16:12, Martyn Ranyard wrote: [...] > This doesn't seem right - a PChar is just a pointer to a character,

where the

Show quoted text 21 lines
Consider the following example (for Delphi): var st: string[10] = 'Hello'; begin writeln(PChar(@st[1]) + ' !!!'); end. The output is: Hello !!! Does this mean we can add strings to pointers? No. Consider the next one: type HonestPChar = ^Char; var st: string[10] = 'Hello'; begin writeln(HonestPChar(@st[1]) + ' !!!'); end.

A PChar is definitely a pointer to char! Strings aren't I have only encountered a problem with more than 255 character using StrPCopy (or maybe StrPas) in Delphi.
Most probably just because they are no longer needed, as Delphi allows you to typecast directly between (Ansi)string and PChar;

Delphi says: Error: Incompatible types: 'string' and 'HonestPChar'
var
  st: PChar = 'Hello';
begin
  writeln(String(st) + ' !!!');
end.

This will work. The + operator works only with strings, not with PChars. BTW, specifying the length of a string will make it a ShortString, which is not compatible with PChars.

> I would have thought that the code behind ansistrings are pchars, but I

may

> be wrong. Delphi's rtl handles strings' operations independently of pchars whenever possible, iirc. (That is, when not mixed, etc.)

No, Delphi (Ansi)Strings are dynamically allocated and null terminated like PChars, and have their lenght prepended like old stings (ShortString or string[xx])

Giovanni Premuda SoftWerk sas
Jonas Maebe
to Nikolai Zhubr: [...] Consider the following example (for Delphi): var st: string[10] = 'Hello'; begin…
Nikolai Zhubr wrote 14 lines
> This doesn't seem right - a PChar is just a pointer to a character, > where the Consider the following example (for Delphi): var st: string[10] = 'Hello'; begin writeln(PChar(@st[1]) + ' !!!'); end. The output is: Hello !!! Does this mean we can add strings to pointers? No. Consider the

Yes and no. In the above example, "pchar(@st[1])" is automatically converted to an (ansi?)string. So the end result is that you are adding two strings.

Show quoted text 12 lines
next one: type HonestPChar = ^Char; var st: string[10] = 'Hello'; begin writeln(HonestPChar(@st[1]) + ' !!!'); end. Delphi says: Error: Incompatible types: 'string' and 'HonestPChar'

That's because pchar is a "special" type. For example, in TP/Delphi you can't access pointer types like arrays (so normally, st[1] already should fail). In FPC this is the same: in the type conversion code, a lot of explicit checks for pchars are done, which fail when you define your own custom type (since in Pascal, two different types are never the same, even if they have exactly the same definition)

BTW, this doesn't fit well enough in my head ;) yet. Its like C belch or something... I'm afraid of pchars.

The magic compiler stuff can indeed be quite confusing if you don't know how things are handled.

Jonas

Florian Klaempfl
to Jonas Maebe
you wrote
fail). In FPC this is the same: in the type conversion code, a lot of explicit checks for pchars are done, which fail when you define your own custom type

No, it doesn't :)

Jonas Maebe
to Florian Klaempfl
Florian Klaempfl wrote 5 lines
>fail). In FPC this is the same: in the type conversion code, a lot of >explicit checks for pchars are done, which fail when you define your own >custom type No, it doesn't :)

It should! :)

Jonas