Re: New versions of VC++ still stuck with function prototypes?

From: Andre Kaufmann (andre.kaufmann.bei_at_t-online.de)
Date: 03/27/05


Date: Sun, 27 Mar 2005 11:39:44 +0200

Arnaud Debaene wrote:
> _R wrote:
>
>>Given that VS2005 has made an effort to clean up the syntax of VC++
>>(in C++/CLI), is there any future plans to do away with function
>>protos, ala C#/VB?
>
> You mean remove the header files? I hope they will never do it!
>

I hope they will (try to) support that in a future standard, since that
could drastically improve compilation speed.

>
>>What are they needed for these days?
>
> - Clean separation of interface and implementation (not clear enough IMHO,
> but still better than in C# or VB).

For that purpose, you donīt need any header file. C++ doesnīt offer any
better separation than the other languages. If you make heavy use of
templates you effectively cannot separate the interface from the
implementation, or have to use code separation "tricks" like the pimpl
idiom.
Some languages are separating their code files into 2 halves. One
interface section and one implementation section. I donīt see any
reason, why that cannot be done in C++ and AFAIK IBM has offered a
proprietary C++ solution. I think that would offer a much better
handling and for template interfaces there wouldnīt be a need for an
export keyword.

> - Limitation of what need to be recompiled when you modify an implementation
> detail : C# compilation model doesn't scale well because each time you
> modify the slightest detail in an assembly, you need to recompile all
> dependent code. With C++, you need only to relink dependencies. Although C#
> or VB.NET compilers are faster than C++ compiler (because the syntax is much
> simplier), it means that it can be difficult to build a huge project with C#
> or VB.
>

If you have a large C++ project, youīll have to use sooner or later
precompiled header files to speed up compilation. And when you touch a
single header file, the C++ compiler has to recompiled the whole
project. Not much better than in other languages.
The syntax of the C++ compiler is complex, but itīs not the only reason
why a C++ compiler needs so much more time, than a C# or VB compiler.
Besides better optimization, the main reason is the separation into
header and implementation files.
Yes - normally there should be only the interface in the header file,
but effectively you will have also implementation code (templates, stl,
windows.h) to include in the header files. And if the project grows, you
   have to permanently think of code separation, so that the compilation
speed wonīt be too slow.

Donīt get me wrong, i love C++ in many aspects, but sometimes i still
prefer other languages because of compilation speed.
If my C# project with 200 units compiles faster completely than a single
C++ unit of my project with also 200 units and header files what is the
advantage of a clear separation in 2 files ?

The C++ compiler could automatically detect (ok not an easy task for a
C++ compiler) if the implementation or the interface has changed and
mark the object file if the implementation or the interface has changed.
Each other C++ file including the changed unit (header + implementation)
file could then simply check if the interface has changed or not. If not
there wouldnīt be a need to recompile the unit.
This could only work, if the usage of macros is restricted and side
effects are disallowed.
And this would perhaps allow to improve compilation speed of templates
too, perhaps this would be a better solution than the export keyword.

I donīt know if the C++ language could be changed that way and if it
would increase compilation speed that much as i would expect.
We will know it if another language offers templates, the way C++ offers
them, too ;-)

And there must be have been a reason, why (AFAIK) IBM tried to implement
something similiar in their C++ compiler .

> Arnaud
> MVP - VC
>
>

Andre



Relevant Pages

  • Re: Avoiding compilation cascades
    ... > cascades by creating the equivalent of C header files. ... > are then tied to these interface files and not the full module. ... Are compilation cascades really that big a problem? ...
    (comp.lang.fortran)
  • Re: Compilation errors in Standard header files
    ... >errors in standard header files supplied by VC++ like stdlib.h, ... >When I write a simple C file, its not giving these compilation erros. ... >C2226: syntax error: unexpected type 'T' ... >C2062: type 'const int' unexpected ...
    (microsoft.public.vc.language)
  • Re: metapost or something? Coordinate system - transformation with cosine...
    ... hmm. ... @q ** Compilation. ... That's CWEB, but you don't really need it. ... GCC looks through the path for header files specified on your system, ...
    (comp.text.tex)
  • Re: New versions of VC++ still stuck with function prototypes?
    ... compilation time is a clean separation of interface from implementation. ... This separation can be accomplished through properly designed header files, ... I expect that we'll see a new language with the expressiveness of C++ ... but with a clean module concept before we see such featues in standar C++. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: New versions of VC++ still stuck with function prototypes?
    ... > that could drastically improve compilation speed. ... you've got nothing to separate a class interface from implementation. ... Concerning templates, ... > precompiled header files to speed up compilation. ...
    (microsoft.public.dotnet.languages.vc)