Sign in Join

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

Mailing lists / fpc-devel / 2008-07

Re: Re: Illegal type conversion: "<enumeration type>"to "TObject"

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Schatzl Thomas

Hello,

Show quoted text 17 lines
From: Craig Peterson Message-ID: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Schatzl Thomas wrote: > This will never compile directly on 64 bit platforms (x64/ppc64) because > afaik sizeof(enum) always sizeof(tobject) there. The original poster > didn't mention his platform afaik. Sorry, Sean was out of the office yesterday. Boian hit it exactly; we're doing this cast to store values in the TStrings Objects[] property. The current platform we're targeting is Linux 32-bit, but we'll probably go to 64-bit at some point too, and it would be nice if the cast continued to work as is. AFAIK, none of the original Delphi code uses MinEnumSize, so it does work there with 1 and 2 byte enumerations as well.

So this is not some regular type cast but some hack for Delphi - I fixed this in trunk by also allowing typecasts from enumerations (formerly only integers were allowed) to objects in Delphi mode. Due to the nature of the hack already present it also works on 64 bit platforms. Sorry for taking so much time (and thanks for your perserverance ;)

However, all other objections against typecasting still apply, i.e. it's imho not too clean to typecast and breaks the -CR functionality and has maybe other issues.

Regards,
Thomas

GMX Kostenlose Spiele: Einfach online spielen und Spaß haben mit Pastry Passion! http://games.entertainment.gmx.net/de/entertainment/games/free/puzzle/6169196

Reply by email

Craig Peterson
to Schatzl Thomas

Thanks Thomas, and the turnaround was definitely faster than I'm used to with Borland. :)

However, all other objections against typecasting still apply, i.e. it's imho not too clean to typecast and breaks the -CR functionality and has maybe other issues.

We're still trying to get the whole project compiling, but once that's done I'm sure we'll start looking into using FPC's additional warnings and checks. At that point we can start reducing our reliance on Delphi hacks.

I am curious about the -CR functionality though. I haven't used it before, but according to the User's Guide it "Generates checks when calling methods...". We're not calling any methods of the "objects" in this case, and I'd be surprised if TStrings was doing anything with them other than copying them around, so why wouldn't this be compatible?

Thanks,
Craig

Reply by email

Jonas Maebe
to Craig Peterson
Craig Peterson wrote 6 lines
I am curious about the -CR functionality though. I haven't used it before, but according to the User's Guide it "Generates checks when calling methods...". We're not calling any methods of the "objects" in this case, and I'd be surprised if TStrings was doing anything with them other than copying them around, so why wouldn't this be compatible?

It verifies more than just method calls (that description is not very good: it verifies whether self actually points to a valid object/class instance in case of method calls, and also in some other cases). It however also verifies class type casts (it basically replaces every tclass1(instance) with "instance as tclass1"), and also enables regular range checking at the same time.

That said, I was apparently wrong in saying that classtype(enum) is incompatible with -CR: the check is only inserted if the type casted entity is also a class type.

Jonas

Reply by email

Boian Mitov
to Schatzl Thomas: So this is not some regular type cast but some hack for Delphi - I fixed this in trunk by…

Hi Thomas,

While your arguments are very true, this is a case where braking the rules comes with indeed less danger. Since the TStrings does not delete the objects, using dummy classes etc. requires a lot of support code and making sure at any point a string is deleted the object to be freed. This comes at a lot of extra code, and is extremely error prone. It almost guarantees that a mistake will be made at some point in complex project, and a memory leak is almost certain. "Illegal" typecasting in this case is indeed the lesser of the two evils, still ugly none the less, but I will take safe over ugly any day ;-) .

With best regards,
Boian Mitov

-------------------------------------------------------------------- Mitov Software
http://www.mitov.com
--------------------------------------------------------------------

Earlier message 11 lines
----- Original Message ----- From: "Schatzl Thomas" To: Sent: Friday, July 18, 2008 2:21 PM Subject: Re: [fpc-devel] Re: Illegal type conversion: "<enumeration type>"to"TObject" > However, all other objections against typecasting still apply, i.e. it's > imho not too clean to typecast and breaks the -CR functionality and has > maybe other issues.

Reply by email