Re: Header Files and Interfaces Yet Again
From: Kai-Uwe Bux (jkherciueh_at_gmx.net)
Date: 06/11/04
- Next message: JKop: "Re: Is this Standard C++: int main(int argC, char* argV[])?"
- Previous message: Stewart Gordon: "Re: OT. joke"
- In reply to: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Next in thread: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Reply: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 09:24:15 -0400
Hi,
These posts are getting a little too long, so I will focus on one point
only.
Steven T. Hatton wrote:
>> The point that I hope to get across is that header files need to provide
>> information to the compiler that is of no concern to the programmer using
>> the library. Private fields of classes are of no concern whatsoever to
>> the user. Nonetheless, a compiler has to know about them at compile time.
>> Therefore, fake headers can not serve as sufficient information to the
>> compiler.
>
> They don't need to. Stroustrups approach is very similar to what you are
> doing. But he actually uses what you call a fake header. There is no rule
> against having multiple declarations appear in the same translation unit.
> I'm not really srue why header files that present things that aren't
> necessary for the client's code should need to be #included in the
> client's
> source file. They should be #included in your source files. What you are
> calling the fake header should be #included in the client's source.
> Stroustrup even #includes the equivilaent in the implementation's header
> to test it for consistency.
and latter:
>> The compiler will need to know a lot more than I want to read in the
>> standard. I do not want the standard to tell me about private members of
>> the container classes.
>
> You really should try to get a copy of Stroustrup's book. It explains how
> both of these can be the case. That is, I get a foo.h user's header file
> and the implementation has a foo_impl.h header file.
That appears to be an interesting concept. But you have me wonder how this
is possible. As you are refering to Java sometimes, let me describe, for
the sake of exposition, what, in my mind, is one of the major conceptual
differences between Java and C++: In Java all obects appear to be handles.
Consider the code:
a = b;
b.some_modifying_method( arg );
My understanding of Java is that the changes inflicted upon b will affect a
as well, after the assignment, a and b are names for the same object.
Whatever you do to it using one name you could as well do using the other.
In C++, this is not true--at least not for the compiler generated
assignment operator.
This difference is important for the ways compiler can go about generating
code. In Java any user defined class could always be represented by a
pointer. Assignment is pointer assignement. Since actual objects are only
created at runtime, it is the linker that must know about the sizes of the
physical objects that the object handles point to. But the compiler can
safely assume that an object handle has the size of one pointer. In C++,
life is more tricky. If the library presents a header:
// file: foo.h
class PhoneDirectory {
// private data fields suppressed.
public:
void insert ( const std::string & name,
const std::string & number );
...
}
and client code says:
// file: main.cc
#include <PhoneDirectory.h>
int main () {
PhoneDirectory dir;
...
}
Then, how is the compiler supposed to deduce the size of the variable
"dir"?
Best
Kai-Uwe
ps.: Please go gentle on me, I have only a very superficial knowledge of
Java, and what I said may grossly misrepresent Java.
- Next message: JKop: "Re: Is this Standard C++: int main(int argC, char* argV[])?"
- Previous message: Stewart Gordon: "Re: OT. joke"
- In reply to: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Next in thread: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Reply: Steven T. Hatton: "Re: Header Files and Interfaces Yet Again"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|