Re: What if the implementation of a class is split into separate files

Ben Elliston <bje@air.net.au>
17 Jul 2004 18:07:27 -0400

          From comp.compilers

Related articles
What if the implementation of a class is split into separate files DrFebruary@yahoo.com (2004-07-13)
Re: What if the implementation of a class is split into separate files bje@air.net.au (Ben Elliston) (2004-07-17)
| List of all articles for this month |

From: Ben Elliston <bje@air.net.au>
Newsgroups: comp.compilers
Date: 17 Jul 2004 18:07:27 -0400
Organization: Comindico Australia - reports relating to abuse should be sent to abuse@comindico.com.au
References: 04-07-013
Keywords: C++, code, optimize
Posted-Date: 17 Jul 2004 18:07:27 EDT

> I came across somebody's code that split the implementation of one
> class into separate files. For example, instead of put
>
> myClass::foo() { }
> and
> myClass::bar() { }
>
> in one, let's say, myClass.cpp, this guy put myClass::foo in
> myClassfoo.cpp and put myClass::bar in myClassbar.cpp.
>
> My question is: 1. what is the difference, if any, in the code that
> the compiler generates? 2. is there any difference on the
> performances between these two ways?


There may be performance differences, depending on the compiler (as
the moderator has mentioned). Some C++ compilers may be capable of
intermodule analysis. So, for example, if code in myClass.cpp calls
myClass::bar(), a capable compiler may be able to inline bar() or
perform other interprocedural optimisations. If the compiler is not
capable, then code in myClass.cpp will have to just make a procedure
call without little understanding of bar()'s definition.


From a correctness perspective, both are equivalent--the linker will
find the methods. From a performance perspective, the differences
could be significant.


Ben


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.