Sign in Join

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

Mailing lists / fpc-devel / 2006-12

generics

12 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Vincent Snijders

Will fpc support generic record declarations like this:

type
   generic TFixedKeyNode<KeySize> = record
     key: array[0..KeySize-1] of char;
     value: dword;
   end;

In other word the type is not parameterized by another type but by an integer used to define the upper limit of an array.

I am thinking of trying to use generics to implement the hashtable with fixed size keys for the k-nucleotide benchmark:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=knucleotide&lang=all

Vincent

Reply by email

Daniël Mantione
to Vincent Snijders

Op Wed, 20 Dec 2006, schreef Vincent Snijders:

Show quoted text 10 lines
Will fpc support generic record declarations like this: type generic TFixedKeyNode<KeySize> = record key: array[0..KeySize-1] of char; value: dword; end; In other word the type is not parameterized by another type but by an integer used to define the upper limit of an array.

Basically, isn't this similar to a schema type like you have in Extended Pascal?

Daniël

Reply by email

Vincent Snijders
to Daniël Mantione
Daniël Mantione wrote 15 lines
Op Wed, 20 Dec 2006, schreef Vincent Snijders: > Will fpc support generic record declarations like this: > > type > generic TFixedKeyNode<KeySize> = record > key: array[0..KeySize-1] of char; > value: dword; > end; > > In other word the type is not parameterized by another type but by an integer > used to define the upper limit of an array. Basically, isn't this similar to a schema type like you have in Extended Pascal?

No idea. I have absolutely no knowledge about Extended Pascal. Can you give a link which describes that?

Vincent

Reply by email

Michael Schnell
to Vincent Snijders: Will fpc support generic record declarations like this: type generic…
Show quoted text 11 lines
Will fpc support generic record declarations like this: type generic TFixedKeyNode<KeySize> = record key: array[0..KeySize-1] of char; value: dword; end; In other word the type is not parameterized by another type but by an integer used to define the upper limit of an array.

Free Pascal seems to support macros (I did not try yet): http://www.freepascal.org/docs-html/prog/progse5.html

With this compile-time variable typedefs should be doable.

-Michael

Reply by email

Daniël Mantione
to Vincent Snijders: No idea. I have absolutely no knowledge about Extended Pascal. Can you give a link which…

Op Wed, 20 Dec 2006, schreef Vincent Snijders:

Show quoted text 21 lines
Daniël Mantione schreef: > > Op Wed, 20 Dec 2006, schreef Vincent Snijders: > > > Will fpc support generic record declarations like this: > > > > type > > generic TFixedKeyNode<KeySize> = record > > key: array[0..KeySize-1] of char; > > value: dword; > > end; > > > > In other word the type is not parameterized by another type but by an > > integer > > used to define the upper limit of an array. > > Basically, isn't this similar to a schema type like you have in Extended > Pascal? No idea. I have absolutely no knowledge about Extended Pascal. Can you give a link which describes that?

http://www.gnu-pascal.de/gpc/Schema-Types.html

Daniël

Reply by email

Daniël Mantione
to Marco van de Voort

Op Wed, 20 Dec 2006, schreef Marco van de Voort:

Show quoted text 10 lines
> Op Wed, 20 Dec 2006, schreef Vincent Snijders: > > > > > In other word the type is not parameterized by another type but by an integer > > used to define the upper limit of an array. > > Basically, isn't this similar to a schema type like you have in Extended > Pascal? Aren't those automatically dynamic?

What do you mean with dynamic? Dynamic memory management: no, static.

Daniël

Reply by email

Marco van de Voort
to Daniël Mantione
Show quoted text 10 lines
Op Wed, 20 Dec 2006, schreef Marco van de Voort: > > > In other word the type is not parameterized by another type but by an integer > > > used to define the upper limit of an array. > > > > Basically, isn't this similar to a schema type like you have in Extended > > Pascal? > > Aren't those automatically dynamic? What do you mean with dynamic? Dynamic memory management: no, static.

Yes, that is what I meant. So just to be clear: you can create a schema type on the stack? Or nest it inside a record, and it remains a single record?

Reply by email

Daniël Mantione
to Marco van de Voort

Op Wed, 20 Dec 2006, schreef Marco van de Voort:

Show quoted text 13 lines
> Op Wed, 20 Dec 2006, schreef Marco van de Voort: > > > > In other word the type is not parameterized by another type but by an integer > > > > used to define the upper limit of an array. > > > > > > Basically, isn't this similar to a schema type like you have in Extended > > > Pascal? > > > > Aren't those automatically dynamic? > > What do you mean with dynamic? Dynamic memory management: no, static. Yes, that is what I meant. So just to be clear: you can create a schema type on the stack? Or nest it inside a record, and it remains a single record?

Yes, confirmed, and if you blockwrite the record (if that is possible in GPC), you write the schema to disk.

Daniël

Reply by email

Vincent Snijders
to Michael Schnell
Michael Schnell wrote 6 lines
No. Generics are more like using a macro when defining a type. So a ":=" copies the memory and not a pointer and they are passed by value into a procedure.

I think you cut too much context. To which question does this give an answer?

Vincent

Reply by email

Michael Schnell
to Vincent Snijders
Show quoted text 10 lines
Michael Schnell schreef: > No. Generics are more like using a macro when defining a type. > > So a ":=" copies the memory and not a pointer and they are passed by > value into a procedure. > > I think you cut too much context. To which question does this give an answer?

(Don't you see the link to the message I answered to in the message tree with your Newsgroup viewer ?)

The question was:

Aren't those automatically dynamic?

So the answer is no, as they are not pointers (like instances of Classes).

-Michael

Reply by email