C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

library questions

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
John Dill
Guest





PostPosted: Fri Feb 27, 2004 2:21 am    Post subject: library questions Reply with 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). 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





PostPosted: Sat Feb 28, 2004 3:35 am    Post subject: Re: library questions Reply with quote



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





PostPosted: Sat Feb 28, 2004 4:00 am    Post subject: Re: library questions Reply with quote



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





PostPosted: Mon Mar 01, 2004 7:31 pm    Post subject: Re: library questions Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.