[fpc-devel] Templates / Generics Syntax

Peter Vreman peter at freepascal.org
Fri Nov 4 15:21:15 CET 2005


> Peter Vreman wrote:
>> I did some tests with g++. It looks like it parses the template
>> 'normally'
>> and don't handle it like a macro. When instantiating the template the
>> generic type is replaced.
>
> What tests did you do to come to this conclusion ? I mean, how can one
> see how g++ parses things ?

Expiriment, feed g++ code with errors in the statements. With macro's
those errors won't be show until the macro is used. But with templates
this is diffent:

template<typename T> class test
{
  public:
    T data;
    string s;
    int i;
    void p()
    {
      show(data);
      i=i*3+data+s;   <--- this is allowed until instantiated
      i=i*3+s;        <--- this is not allowed
      data=data;
    }
};


>> full node tree when the generic is instantiated. But that means that it
>> must be known that
>
> ....yessss? :-)

This is more important than the syntactical sugar. The rules where to
declare generics and how/when they are parsed must be known. The syntax
can be added in the end.






More information about the fpc-devel mailing list