Topic: Breaking down dependencies
Author: Reico GmbH <Entwicklung@reico.de>
Date: 1999/12/09 Raw View
Hi,
> - The type definition cannot be "hijacked" by programmers adding
> in their own additions later.
> - The definition is less subject to violations of the One-Definition
> Rule, which could be a problem if incomplete member types were
> independently completed in different translation units.
OK, that would become more problematic than it is now. But you could
write now:
----structB.h----
struct B {
A a;
};
----translation-unit_1.cpp----
include "structA_v1.h"
include "structB.h"
...
----translation-unit_2.cpp----
include "structA_v2.h"
include "structB.h"
That's not common practice, I know. But it could also happen due to some
subtile pre-processing. I know, my suggestion could cause some accidents
more - but who use a class name twice in the same namespace, have to
know anyway, what he/she do.
> These properties promote type safety and run-time effieciency. (More
> things are known at compile time and do not need to be deferred
> until run time.)
My compiler would generate exactly the same code as a standard compiler.
The only different thing is the delay of the size calculation during
compile time until the size is first needed. If the size couldn't
calculated, it's an error.
Best regards
Olaf Krzikalla
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Steve Clamage <stephen.clamage@sun.com>
Date: 1999/12/08 Raw View
Reico GmbH wrote:
>
> I've got an idea how to break down some dependencies, especially
> dependencies to private data member types.
>
> First, let me introduce some things:
>
> 1. A complete defined class is a class defined as usual.
>
> 2. An incomplete defined class is a defined class, where data members
> may be incomplete defined or just declared. Base classes must be defined
> (maybe incomplete).
>
> 3. Built-in types, pointers and references are complete defined.
You describe a possible language design, but it is fundamentally
different from basic C++ design choices.
In C++, a type has single, complete definition. That means that,
among other things:
- The type definition cannot be "hijacked" by programmers adding
in their own additions later.
- The definition is less subject to violations of the One-Definition
Rule, which could be a problem if incomplete member types were
independently completed in different translation units.
- A type is either completely opaque or completely defined. If defined,
its size and everthing else about it is known at compile time.
These properties promote type safety and run-time effieciency. (More
things are known at compile time and do not need to be deferred
until run time.)
A better way to get the effect you want would be a module system
similar to Ada, Modula or Borland Pascal. There would be single complete
definition of a type, but only the public interface would be exposed
to users of the type. The compiler keeps track of the rest of the
information for you. C++ could get a module system with little
change to fundamental language design.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Reico GmbH <Entwicklung@reico.de>
Date: 1999/12/07 Raw View
Hi,
I've got an idea how to break down some dependencies, especially
dependencies to private data member types.
First, let me introduce some things:
1. A complete defined class is a class defined as usual.
2. An incomplete defined class is a defined class, where data members
may be incomplete defined or just declared. Base classes must be defined
(maybe incomplete).
3. Built-in types, pointers and references are complete defined.
Why shouldn't it be possible to allow incomplete defined classes ?
I think, it's easy to realize and don't introduce new language features.
A compiler could calculate the size of a class or it's members on demand
(on really demand, for just the definition of a class the size isn't of
interest). If this couldn't performed, the compiler generates an error
and reports the type name not complete defined yet.
Note that it's possible to create an incomplete defined class
and make it to a complete defined class later by including the
appropriate data types.
An incomplete defined class can be used to call their member functions
(virtual, non-virtual, static) - one of the most needed things.
Assume that there are no public data members. So the only files, where
dependencies to the types of data members will generated, is the
implementation of the class (usually in one file), these files, where
instances of the class will be constructed and - unfortunately - files,
where inline functions will be called. But the wide range of files,
where a class is just used by calling their outline member functions
aren't dependent to the data member types.
I know it's not the really big deal to breaking down the dependencies to
the private part of a class, but it's a little step in this direction
and I think, it can save some compile time.
To give a better understanding, I could post some examples.
Best regards
Olaf Krzikalla
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]