Recent

Author Topic: Units  (Read 1035 times)

guest65405

  • Guest
Units
« on: March 29, 2020, 07:23:04 pm »
I have a bunch of units and I want to include them all into a big unit. This is what the C library does, it has a header whose content just include other headers.

Would the same way work with Pascal? So when I use the big unit all of the small units are available to me? Or have I need to use $I to actually include all of the small units?

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: Units
« Reply #1 on: March 29, 2020, 08:00:41 pm »
It is not possible to propagate the interfaces of units through other units that use them.

Including them all in a different unit is possible (if you take care with ifdefs that you don't end up with multiple interface/implementation sections etc), but this will cause problems if both this big unit and the individual units are used in the same problem. The reason is that Pascal types generally do not use structural equivalence (unlike C types), and hence structured types identically declared in the big unit and in the small units will be incompatible.

440bx

  • Hero Member
  • *****
  • Posts: 4015
Re: Units
« Reply #2 on: March 29, 2020, 08:13:11 pm »
I have a bunch of units and I want to include them all into a big unit. This is what the C library does, it has a header whose content just include other headers.
That's a terrible idea.  One of the many problems in C is the lack of modularity and the need to have headers include other headers that include the headers that were already included someplace else.  It's pedestrian, baroque, and resembles the path a drunkard takes to get home. 

Would the same way work with Pascal? So when I use the big unit all of the small units are available to me? Or have I need to use $I to actually include all of the small units?
It might work but, it's a little bit like having a gun and asking someone if you can shoot yourself in the foot with it.  Odds are the answer is "yes" but, the question raises concerns about the mental stability of the individual asking it.

(Modern) Pascal is modular and organized, C is neither.  You don't want to import C's mess into Pascal.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Otto

  • Full Member
  • ***
  • Posts: 226
Re: Units
« Reply #3 on: March 29, 2020, 11:25:08 pm »
Hello 440bx
I agree FPC is well organized.

A short time ago I opened a thread on a topic in a somewhat related way. The main topic is the ability to use PartialUnits, which consist of a single unit fragmented into distinct parts of code. It also discusses the opposite argument for merging multiple separate Units (thanks to soerensen3), that is the arguments of this thread.

Otto.
Kind regards.

 

TinyPortal © 2005-2018