A c++ puzzle for you gurus
Clemens Hintze
ml-dgfly_users at qiao.in-berlin.de
Tue Dec 19 07:25:15 PST 2006
Am 19.12.2006 um 11:41 schrieb Miguel Sousa Filipe:
Hi,
Hello,
On 12/18/06, walt <wa1ter at myrealbox.com> wrote:
(...)
a header file 'include' a source file before, so I didn't even
look at
(...)
Is this practice specific to c++ ? (If you know of any examples of c
code doing this, please point them out. Thanks!)
This is not specific to c++, its more specific of aplications that
have the source code badly organized, and with twised file dependency
chains.
excuse me if I dare to not agree with you here. If using templates in
C++ it is not that seldom that one use a .hpp that contains template
declarations and includes a .cpp file containing the implementation
of those templates.
The reason is to get the declaration (interface) separated from the
implementation in different files as usual.
But the C++ compiler has to see the implementation of a template
before it is used. Therefore C++ defines a keyword 'export' that
allow template definitions reside in other compilation units as
theirs declarations for separating purposes.
As not all compiler support 'export' yet, the 'trick' with the .hpp
including its .cpp is the only way to separate a template definition
from its implementation.
But I have to confess, as I did not looked into mtasker.hpp, I do not
know if my babble above is a valid reason for mtasker.hpp including
mtasker.cpp, or if it is really a sign of bad source code
organization. I only want to point out, that it isn't a pattern for
bad code organization!
So, it's possible to have "bad" organization like that in C too.
For C sources, I would tend to agree with you, as I do not see any
reason for a header to include a .c source.
Best regards,
Clemens.
More information about the Users
mailing list