 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Dill Guest
|
Posted: Fri Feb 27, 2004 2:21 am Post subject: library questions |
|
|
I have a some questions about how to organize source code. The main
concern is that when developing libraries with templates, I typically
leave the implementation in the header so that the compiler can
auto-generate the instantiation types automatically. If I compile the
code into a library, then I usually fix the types which my templates
can be instantiated.
There are some functions which are rather large and probably shouldn't
be inlined (which I believe is the case when the function
implementation is defined in the header along with the function
declaration). I could put this in a source file to be compiled, but
that seems to limit the instantiation types that are allowed. What
techniques are there to select from?
Also, a little off-topic, I'm getting closer to publishing my library
someplace online. I'm currently using my own home-grown makefile
system for linux, but want the library to be usable in a more
automated installation. I don't want anything too fancy. I also need
to worry about license and copyright stuff. If there is a better
forum for these questions, please let me know. Thanks.
John
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Benjamin Mesing Guest
|
Posted: Sat Feb 28, 2004 3:35 am Post subject: Re: library questions |
|
|
Hello,
| Quote: | (which I believe is the case when the function
implementation is defined in the header along with the function
declaration).
No - they are only inline if they are defined in the class definition block. |
Consider the following header file:
---A.h---
class A
{
void func() { do_something(); } // this is inline
void funcB(); // this not
void funcC(); // this is inline again - see below
}
void A::funcB()
{
do_another_thing();
}
inline void A:funcC()
{
do_yet_another_thing();
}
Greetings Ben
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Sat Feb 28, 2004 4:00 am Post subject: Re: library questions |
|
|
John Dill wrote:
| Quote: | I have a some questions about how to organize source code. The main
concern is that when developing libraries with templates, I typically
leave the implementation in the header so that the compiler can
auto-generate the instantiation types automatically. If I compile the
code into a library, then I usually fix the types which my templates
can be instantiated.
There are some functions which are rather large and probably shouldn't
be inlined (which I believe is the case when the function
implementation is defined in the header along with the function
declaration).
|
No, that doesn't cause them to be compiled inline. Defining a class
with the "inline" specifier or within a class definition requests that
it be compiled inline. The compiler will make the decision whether to
inline based upon the presence of such requests, the estimated size of
the inline code, the estimated size of an out-of-line call and
optimisation options passed to it. However, older compilers never
compile functions inline if they are defined in another translation
unit, so defining them in a header may make a difference.
| Quote: | I could put this in a source file to be compiled, but
that seems to limit the instantiation types that are allowed. What
techniques are there to select from?
|
That does limit the instantiation types unless you use export,
which very few compilers (maybe still just the one?) support yet.
| Quote: | Also, a little off-topic, I'm getting closer to publishing my library
someplace online. I'm currently using my own home-grown makefile
system for linux, but want the library to be usable in a more
automated installation. I don't want anything too fancy.
|
A common approach is to use GNU's automake and autoconf, but so far as
I can see those are quite "fancy". So long as you only depend on
those parts of standard C++ that are widely implemented correctly you
can probably do without them. All you will need to do is to make
sure you use the CXX and CXXFLAGS variables consistently in the
Makefile so that users can select any C++ compiler. You should
probably test your Makefile with several versions of make, too, or
else use GNU make and require other users to do the same.
| Quote: | I also need to worry about license and copyright stuff. If there is
a better forum for these questions, please let me know. Thanks.
|
I'm afraid I don't know what the best place is to ask about that.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Mon Mar 01, 2004 7:31 pm Post subject: Re: library questions |
|
|
I wrote:
| Quote: | No, that doesn't cause them to be compiled inline. Defining a class
with the "inline" specifier or within a class definition requests that
it be compiled inline.
|
The first "class" should of course be "function".
| Quote: | However, older compilers never compile functions inline if they are
defined in another translation unit, so defining them in a header
may make a difference.
|
I should really have said "not defined in the same translation unit as
the caller" rather than "defined in another translation unit".
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|