BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

includes vs units

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical)
View previous topic :: View next topic  
Author Message
Robby Tanner
Guest





PostPosted: Wed Sep 07, 2005 3:36 pm    Post subject: includes vs units Reply with quote



I'm translating some C headers to pascal units. There appears to be a
slightly different behaviour between them when compiling.

An example,

If header1.h includes header2.h then the application.c has access to
constants and types of both headers, right? This does not appear to be the
case where header1.pas uses header2.pas. Application.pas does not seem to
have access to header2 definitions. Is the observation correct? Is this
obvious and I've just never noticed it? Is the former behaviour part of the
reason that C requires multipass compiling?

Is the only solution to add more files to the uses or is there an
include-type directive in OP?

Sorry if I'm in the wrong group. It was 50-50 which to go in and I didn't
want to cross-post.

Regards,
Rob


Back to top
Andreas Hausladen
Guest





PostPosted: Wed Sep 07, 2005 4:25 pm    Post subject: Re: includes vs units Reply with quote



borland.public.delphi.* would be the better group.

Robby Tanner wrote:

Quote:
Is the observation correct?

Yes, it is correct.

Quote:
Is the only solution to add more files to the uses or is there an
include-type directive in OP?

Delphi uses {$I filename.inc} / {$INCLUDE filename.inc} for file
inclusion. But then you cannot have a unit-structure in the inc file. And
if the {$I ...} is placed before the "implementation" keyword you cannot
implement functions.


--
Regards,

Andreas Hausladen
(http://andy.jgknet.de/blog)

Back to top
Harold Howe [TeamB]
Guest





PostPosted: Wed Sep 07, 2005 4:36 pm    Post subject: Re: includes vs units Reply with quote



Robby Tanner wrote:
Quote:
If header1.h includes header2.h then the application.c has access to
constants and types of both headers, right? This does not appear to be the
case where header1.pas uses header2.pas. Application.pas does not seem to
have access to header2 definitions. Is the observation correct?

Yes. This is the way pascal, c# and java all work. In C and C++,
#include physically pastes the contents of header1.h into your source
file during compilation. By induction, whatever header1.h includes will
also be pasted in.

Pascal, C#, and java do not employ a physical inclusion model like this.
When you say that you are using a unit, you are only using that unit.
Whatever that unit imports is encapsulated.

PS: Pascal does have physical inlude directive, but it is rarely used.

H^2

Back to top
Robby Tanner
Guest





PostPosted: Wed Sep 07, 2005 5:57 pm    Post subject: Re: includes vs units Reply with quote


"Andreas Hausladen" <AndreasDOTHausladen (AT) gNOMAILmx (DOT) de> wrote

Quote:
borland.public.delphi.* would be the better group.

Robby Tanner wrote:

Delphi uses {$I filename.inc} / {$INCLUDE filename.inc} for file
inclusion. But then you cannot have a unit-structure in the inc file. And
if the {$I ...} is placed before the "implementation" keyword you cannot
implement functions.

What do you mean by a unit-structure?

I'm guessing {$I ...}is not highly recommended.

Rob



Back to top
Robby Tanner
Guest





PostPosted: Wed Sep 07, 2005 5:58 pm    Post subject: Re: includes vs units Reply with quote


"Harold Howe [TeamB]" <hhowe (AT) dontcallmehoward (DOT) com> wrote

Quote:
Robby Tanner wrote:

Pascal, C#, and java do not employ a physical inclusion model like this.
When you say that you are using a unit, you are only using that unit.
Whatever that unit imports is encapsulated.

Is there any way to expose what the unit imports?



Back to top
Andreas Hausladen
Guest





PostPosted: Wed Sep 07, 2005 6:04 pm    Post subject: Re: includes vs units Reply with quote

Robby Tanner wrote:

Quote:
What do you mean by a unit-structure?

unit myunit;

interfaces
....
implementation
....
end.


Quote:
I'm guessing {$I ...}is not highly recommended.

It's not used that often in Delphi applications. (FreePascal uses $I all
over the place to reduce IFDEFs)


--
Regards,

Andreas Hausladen
(http://andy.jgknet.de/blog)

Back to top
Helmut Giese
Guest





PostPosted: Wed Sep 07, 2005 6:51 pm    Post subject: Re: includes vs units Reply with quote

On Wed, 7 Sep 2005 20:04:51 +0200, "Andreas Hausladen"
<AndreasDOTHausladen (AT) gNOMAILmx (DOT) de> wrote:

Quote:
I'm guessing {$I ...}is not highly recommended.

It's not used that often in Delphi applications. (FreePascal uses $I all
over the place to reduce IFDEFs)
IIRC, back in the (very) old days we used $i to include .obj files,

usually functions written in assembler for speed.
Helmut Giese

Back to top
Ed Mulroy
Guest





PostPosted: Wed Sep 07, 2005 7:10 pm    Post subject: Re: includes vs units Reply with quote

FYI: In the Turbo Pascal days the editor was limited to a very small source
file and there was no facility for using multiple source files for a program
other than the {$I directive.

.. Ed

Quote:
Helmut Giese wrote in message
news:431f3615.5691005 (AT) forums (DOT) borland.com...

I'm guessing {$I ...}is not highly recommended.

It's not used that often in Delphi applications. (FreePascal uses $I all
over the place to reduce IFDEFs)

IIRC, back in the (very) old days we used $i to include .obj files,
usually functions written in assembler for speed.



Back to top
Andreas Hausladen
Guest





PostPosted: Wed Sep 07, 2005 7:21 pm    Post subject: Re: includes vs units Reply with quote

Helmut Giese wrote:

Quote:
IIRC, back in the (very) old days we used $i to include .obj files,

That was $L(ink) not $I(nclude) in TurboPascal. I used $L for "including"
the BGI driver and fonts.


--
Regards,

Andreas Hausladen
(http://andy.jgknet.de/blog)

Back to top
Robby Tanner
Guest





PostPosted: Wed Sep 07, 2005 8:11 pm    Post subject: Re: includes vs units Reply with quote


"Andreas Hausladen" <AndreasDOTHausladen (AT) gNOMAILmx (DOT) de> wrote

Quote:
Robby Tanner wrote:

What do you mean by a unit-structure?

unit myunit;

interfaces
...
implementation
...
end.

So what would be used instead of the unit structure?



Back to top
Andreas Hausladen
Guest





PostPosted: Wed Sep 07, 2005 8:43 pm    Post subject: Re: includes vs units Reply with quote

Robby Tanner wrote:

Quote:
So what would be used instead of the unit structure?

A "normal" file. Your included file must be treated as it would be in the
file that includes it at exactly this position:

main.pas:
unit main;
interface
bla
{$I myIntfInc.inc}
bla
implementation
{$I myImplInc.inc}
end.

myIntfInc.inc: no function boddy is allowed here because we are in the
interface-section
myImplfInc.inc: everything here is only available to the main.pas (if no
prototype is declared in the interface-section)


--
Regards,

Andreas Hausladen
(http://andy.jgknet.de/blog)

Back to top
Helmut Giese
Guest





PostPosted: Thu Sep 08, 2005 11:00 am    Post subject: Re: includes vs units Reply with quote

On Wed, 7 Sep 2005 21:21:37 +0200, "Andreas Hausladen"
<AndreasDOTHausladen (AT) gNOMAILmx (DOT) de> wrote:

Quote:
Helmut Giese wrote:

IIRC, back in the (very) old days we used $i to include .obj files,

That was $L(ink) not $I(nclude) in TurboPascal. I used $L for "including"
the BGI driver and fonts.
Ah, yes, I think you're right. Well, it's been a while ...

Best regards
Helmut Giese

Back to top
Roger Lascelles
Guest





PostPosted: Fri Sep 09, 2005 7:56 am    Post subject: Re: includes vs units Reply with quote

"Harold Howe [TeamB]" <hhowe (AT) dontcallmehoward (DOT) com> wrote

Quote:
Robby Tanner wrote:
If header1.h includes header2.h then the application.c has access to
constants and types of both headers, right? This does not appear to be
the
case where header1.pas uses header2.pas. Application.pas does not seem
to
have access to header2 definitions. Is the observation correct?


PS: Pascal does have physical inlude directive, but it is rarely used.

A .pas file contains two main sections - firstly Interface and secondly
Implementation.

The Interface section of a .pas file is function declarations, global
variables and class type declarations which you want to share. This is
roughly the stuff you would put in a .h file .

Implementation contains basically the guts of functions and objects -
"private" sort of stuff you don't want or need to share. This is roughly
equivalent to the stuff you would put in a .C file.

It is roughly as if every .pas file has a .h file built in - the interface
section.

Whereas the C compiler simply inserts entire files with #include, Pascal has
the USES clause, which tells the compiler to read the implementation section
of a file - but read it in a special way - for example a variable is not
defined a second time, function declarations never need a body and class
type declarations don't need to be fulfilled with member functions. Because
the compiler "understands" what USES means, it becomes an intelligent helper
and you don't need all those techniques of .h file management. Basically,
you just advertise stuff in the implementation section of each .pas file and
all is well. The order of magnitude compiler speed advantage of Borland
Pascal is partly due to this.

You can add USES to either or both of the implementation and Interface
sections:

Interface

uses SysUtils


Implementation

uses Math;

In Interface, you USES a pas file if it contains a type declaration you need
for interpretation of the stuff in the Interface section.

If implementation, you USES a pas file if it contains a type or variable
declaration you need.


It all becomes clear if you grab the source for some simple Delphi project
from the net and look at a couple of pas files.


Roger Lascelles



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.