Ask a Question related to UNIX Programming, Design and Development.
-
Rene Eng #1
Re: Keeping the template implementation in .C
Hi there.
"qazmlp" <qazmlp1209@rediffmail.com> schrieb im Newsbeitrag
news:db9bbf31.0307270827.a3053f4@posting.google.co m...I'd say it would not work at all!> It is advised to have the template implementation inside header files.
> But, Say, I keep the implementation in .C file. Are there any run time
> problems expected out of this or this is simply a link time problem?
>
It is necessary to compile the whole template code with the type of the
template parameter known, otherwise the compiler can not generate the
correct object code and can not check if the template parameter meets all
requirements (like operators etc.)
In other words: You can create an object of a template module and then
use this object code for different instantiations of the template.
One solution to this problem is to place the definition in the .h file and
the implementation in the .cpp file, but then you have to include the
..cpp file from the .h file, exactly the other way round than it is normally
done.
May be confusing if somebody else is looking at the code.
Since the latter is not possible there is nothing to compare against.> Also, I would like to confirm whether having the template
> implementation in .h will increase the executable size for any reason
> compared to its size when the implementation is kept in a .C file.
However, the size of your executable will be larger since each template
instantiation generates a new class with all the code of the template.
hth
René
=======================================
C++ sources, cross-platform (UNIX and WinTel) and
covering several topics: [url]http://gemini.futurezone.com[/url]
Rene Eng Guest
-
web cam implementation
Hello: Does anyone know of a way to implement a web cam with 30 second interval picture updates? This would be placed in a studio setting (radio)... -
MD5 implementation
I need to use MD5 to generate a hash of a string. It needs to be compatible with the MD5 implementation in PHP. public string ComputeMD5(string... -
RSA implementation for PHP
Hi @ll, Is there a RSA library for php available? Has somebody any samples to decrypt a encrypted message with the public key given in a... -
RSA implementation of PHP
Hi @ll, Is there a RSA library for php available? Has somebody any samples to decrypt a encrypted message with the public key given in a... -
NAT implementation on AIX 5.x
Hi: I have a need to write my own version of NAT for AIX 5.x. I have been able to do this on HP-UX by using a STREAMS module and DLPI approach.... -
Peter van Merkerk #2
Re: Keeping the template implementation in .C
> > It is advised to have the template implementation inside header files.
That is not entirely true, if the compiler supports the export keyword,>> > But, Say, I keep the implementation in .C file. Are there any run time
> > problems expected out of this or this is simply a link time problem?
> I'd say it would not work at all!
> It is necessary to compile the whole template code with the type of the
> template parameter known, otherwise the compiler can not generate the
> correct object code and can not check if the template parameter meets all
> requirements (like operators etc.)
template definitions can be put in a .cpp file. Unfortunately very few
compilers currently do support this keyword. AFAIK only compilers based on
the EDG front end support this keyword.
normally> In other words: You can create an object of a template module and then
> use this object code for different instantiations of the template.
>
> One solution to this problem is to place the definition in the .h file and
> the implementation in the .cpp file, but then you have to include the
> .cpp file from the .h file, exactly the other way round than it isWell it is possible, but it is questionable if it will make a big> done.
> May be confusing if somebody else is looking at the code.
>>> > Also, I would like to confirm whether having the template
> > implementation in .h will increase the executable size for any reason
> > compared to its size when the implementation is kept in a .C file.
> Since the latter is not possible there is nothing to compare against.
difference, since basically every time a template is instantiated code
specific for that instantiation must be generated. The only potential saving
I can see is that it might be easier to share code that is independant of
template parameters.
There are ways to avoid, or at least reduce code bloat caused by template> However, the size of your executable will be larger since each template
> instantiation generates a new class with all the code of the template.
classes.
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl
Peter van Merkerk Guest
-
Mike Spencer #3
Re: Keeping the template implementation in .C
qazmlp wrote:
This will work, you'll just have to add explicit instantiations in> It is advised to have the template implementation inside header files.
> But, Say, I keep the implementation in .C file. Are there any run time
> problems expected out of this or this is simply a link time problem?
>
your .C file for the specializations you need, as the compiler can't
do it for you (without export). You might want to do this if
your implementation requires you to include other header files;
this way you only need to include them in your .C file and users of
your header file will not depend on them.
Mike
--
[url]http://www.lazycplusplus.com/[/url]
The Lazy C++ Programmer's Tool
Mike Spencer Guest



Reply With Quote

