Sign in Join

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

Mailing lists / fpc-devel / 2008-10

circular uses clauses

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi.

Quote from CodeGear news
"circular uses clauses - why can't I declare two classes in two units that refer to each other? Why doesn't forward declarations cope with this? I've got this feature in C, C++ and C# why not Delphi?"

That's a good question... Why can't FPC allow that either? I don't know the internals of FPC, but can't FPC simply keep a list of used units as it compiles, so it simply skips any later references. What is the technical issue? I'm just curious here.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

ik
to Graeme Geldenhuys

The difference between include and uses is that include just drop everything inside the file that is using it, uses is also adding namespace and you do not share the same content.
The problem with circular issues, is that it really hard to debug problems, and it usually cosing more headacks then solving problems.

That's at least the reason why I think the FPC team does not allow such behavior (there might be additional reasons for this).

Ido

Graeme Geldenhuys wrote 24 lines
Hi. Quote from CodeGear news "circular uses clauses - why can't I declare two classes in two units that refer to each other? Why doesn't forward declarations cope with this? I've got this feature in C, C++ and C# why not Delphi?" That's a good question... Why can't FPC allow that either? I don't know the internals of FPC, but can't FPC simply keep a list of used units as it compiles, so it simply skips any later references. What is the technical issue? I'm just curious here. Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/ _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Joao Morais
to Graeme Geldenhuys: Hi. Quote from CodeGear news "circular uses clauses - why can't I declare two classes in…
Graeme Geldenhuys wrote 6 lines
Hi. Quote from CodeGear news "circular uses clauses - why can't I declare two classes in two units that refer to each other? Why doesn't forward declarations cope with this? I've got this feature in C, C++ and C# why not Delphi?"

Because a Pascal compiler parses the interface section of an unit only once, ...

That's a good question... Why can't FPC allow that either? I don't know the internals of FPC, but can't FPC simply keep a list of used units as it compiles, so it simply skips any later references. What is the technical issue? I'm just curious here.

... and the interface section of an unit need to be parsed before used by another one?

Regards, - Graeme -
Joao Morais

Reply by email

Graeme Geldenhuys
to Joao Morais
Joao Morais wrote
Because a Pascal compiler parses the interface section of an unit only once,

That would make sense. And probably the reason why FPC and Delphi are such fast compilers compared to C compilers.

Thanks for the info.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Daniël Mantione
to Graeme Geldenhuys

Op Fri, 3 Oct 2008, schreef Graeme Geldenhuys:

Show quoted text 6 lines
On Fri, Oct 3, 2008 at 2:31 AM, Joao Morais wrote: > > Because a Pascal compiler parses the interface section of an unit only once, That would make sense. And probably the reason why FPC and Delphi are such fast compilers compared to C compilers.

Yes, the interface contains all information the compiler needs to call a procedure. Once this is known the compiler can call procedures in a unit without having compiled the implementation yet. This is why implementations can use each other (a procedure call to a not yet compiled unit is no problem), but interfaces cannot (a reference to a type in a not yet compiled interface is problematic, because it affects how procedures are called).

Daniël

Reply by email

Marco van de Voort
to Graeme Geldenhuys: Hi. Quote from CodeGear news "circular uses clauses - why can't I declare two classes in…

In our previous episode, Graeme Geldenhuys said:

Show quoted text 10 lines
Quote from CodeGear news "circular uses clauses - why can't I declare two classes in two units that refer to each other? Why doesn't forward declarations cope with this? I've got this feature in C, C++ and C# why not Delphi?" That's a good question... Why can't FPC allow that either? I don't know the internals of FPC, but can't FPC simply keep a list of used units as it compiles, so it simply skips any later references. What is the technical issue? I'm just curious here.

Why do I have to put my files in a directory hierarchy and central (GAC) registries in C# and Java? Why can't I just throw all in one dir and let the compiler figure it out, like in FPC ?

Reply by email

Graeme Geldenhuys
to Marco van de Voort
Marco van de Voort wrote
Why do I have to put my files in a directory hierarchy and central (GAC) registries in C# and Java? Why can't I just throw all in one dir and let the compiler figure it out, like in FPC ?

I agree! The file names could contain the namespace with a dot notation. FPC rules! :-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Graeme Geldenhuys

In our previous episode, Graeme Geldenhuys said:

Show quoted text 6 lines
> Why do I have to put my files in a directory hierarchy and central (GAC) > registries in C# and Java? Why can't I just throw all in one dir and let the > compiler figure it out, like in FPC ? I agree! The file names could contain the namespace with a dot notation. FPC rules! :-)

The point is that you can't see such limitations separate from how compilers find files, how files import eachother, their parsing and error generation model etc.

So trying to compare two systems that chose opposite ways of working in this regard are next to useless.

That doesn't mean entirely nothing can be done though, actually I believe older 1.0.x did try to solve simple mutual importing by recompiling units that reference eachother till their CRC stopped changing. It was abandoned since it was pretty unstable (and postponed for a module rewrite that must still happen).

Note however that IIRC this only worked for classes that did NOT reference eachother, IOW there was only for the case where the units didn't contain "type loops"

Reply by email

peter green
to Joao Morais: Because a Pascal compiler parses the interface section of an unit only once, ... ... and…
Because a Pascal compiler parses the interface section of an unit only once, ...

IMO what would fix a lot of the problem would be a "cross unit forward declaration", that is a way to tell a compiler "this type is a class type declared in unit x that is all you need to know for now" (afaict that is all the compiler needs to know to compile a function prototype or similar)

The current situation means that a set of interrelated classes often must either all be put in the same unit or do a lot of typecasting.

Reply by email

Joao Morais
to peter green
peter green wrote 12 lines
> > Because a Pascal compiler parses the interface section of an unit only > once, ... IMO what would fix a lot of the problem would be a "cross unit forward declaration", that is a way to tell a compiler "this type is a class type declared in unit x that is all you need to know for now" (afaict that is all the compiler needs to know to compile a function prototype or similar) The current situation means that a set of interrelated classes often must either all be put in the same unit or do a lot of typecasting.

...instead of create 10 lines of 10 units within the uses declaration in order to use all that related classes. The former is far better imho.

Joao Morais

Reply by email