Sign in Join

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

Mailing lists / fpc-pascal / 2012-02

Alternative to generic advanced records

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Kornel Kisielewicz

Ok, advanced records in 2.6.0 are it seems buggy as hell (with optimizations on), so I'm searching for an alternative. For the simple case objects work quite well, but for generics I have a problem.

This is part of the code:

  generic TGVector3<T> = packed record
{... types}
  public
    class function Create( aX : T = 0; aY : T = 0; aZ : T = 0 ) :
TGVector3; static;
{... functions}
    class operator +( const A, B : TGVec3 ) : TGVector3;
{... other operators}
    class operator Explicit( const A : array of T ) : TGVector3;
{... properties etc}
  end;

The generic record has a lot of utility functions and operators, and is used in specializations for Single, Double, Integer, Byte and one custom type, so rewriting it as not-generic is out of the question. Now, I'd really like to convert it to an object, but objects do not support built-in operators (or do they?). Any ideas how to circumvent that?

regards, Kornel Kisielewicz http://chaosforge.org/

Reply by email

Sven Barth
to Kornel Kisielewicz
Kornel Kisielewicz wrote 24 lines
Ok, advanced records in 2.6.0 are it seems buggy as hell (with optimizations on), so I'm searching for an alternative. For the simple case objects work quite well, but for generics I have a problem. This is part of the code: generic TGVector3<T> = packed record {... types} public class function Create( aX : T = 0; aY : T = 0; aZ : T = 0 ) : TGVector3; static; {... functions} class operator +( const A, B : TGVec3 ) : TGVector3; {... other operators} class operator Explicit( const A : array of T ) : TGVector3; {... properties etc} end; The generic record has a lot of utility functions and operators, and is used in specializations for Single, Double, Integer, Byte and one custom type, so rewriting it as not-generic is out of the question. Now, I'd really like to convert it to an object, but objects do not support built-in operators (or do they?). Any ideas how to circumvent that?

Even if objects would support operator overloads this would not solve your problem. The above operator overloads simply won't work with generics in 2.6.0. I'm working on the issue in 2.7.1, but it's not completely trivial. And no, a merge to 2.6.1 is - in my opinion - out of the question, because the changes in the implementation of generics between 2.6.0 and 2.7.1 are very massive (and they get more the more bugs I fix).

[Though this bugfix might even have a chance of being mergeable, but I won't make any promises that it will be the case in the end]

Regards,
Sven

Reply by email

Paul Ishenin
to Kornel Kisielewicz: Ok, advanced records in 2.6.0 are it seems buggy as hell (with optimizations on), so I'm…

08.02.12 2:52, Kornel Kisielewicz пишет:

Ok, advanced records in 2.6.0 are it seems buggy as hell (with optimizations on), so I'm searching for an alternative. For the simple case objects work quite well, but for generics I have a problem.

That's why it is always good to test FPC trunk versions - there you can influence on what will be released.

Btw, did you report about all found bugs in advanced records? I've fixed 3 related bugs and the fixes are in trunk.

Best regards,
Paul Ishenin

Reply by email