473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to exploit "export"


I have a few really long template functions. They belong in a source
file... and thus must be "exported".

Seeing as how few compilers support "export", could someone please point
me to a webpage/post that gives a very decent method of exploiting
"export" for those compilers that *do* export it, while still remaining
compatible with the defective compilers (which are in the majority!).

I've seen in the comp.lang.c++ FAQ that you can do:

#ifndef SUPPORT_EXPORT
#define export /* Nothing */
#endif

and so on. I works fine, but I just thought I'd check to see if there's
any better ideas before I go modifying all of my code...
-Tomás
Mar 6 '06 #1
8 1823
Tomás wrote:
I have a few really long template functions. They belong in a source
file... and thus must be "exported".


What make you believe they belong in a source file?

A common method to use is to put the templates in a *.hpp or *.hxx
file, and than add an include to the header at the bottom.

#ifndef FOO_H_
#define FOO_H_

template<class T>
class foo
{
public:
//member declartion here
};

#include "foo.hpp" //Put your long template implementation here

#endif // FOO_H_

However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is even
true of the TWO compilers that due support export keyword.

Mar 6 '06 #2

Axter wrote:
Tomás wrote:
I have a few really long template functions. They belong in a source
file... and thus must be "exported".


What make you believe they belong in a source file?

A common method to use is to put the templates in a *.hpp or *.hxx
file, and than add an include to the header at the bottom.

#ifndef FOO_H_
#define FOO_H_

template<class T>
class foo
{
public:
//member declartion here
};

#include "foo.hpp" //Put your long template implementation here

#endif // FOO_H_

However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is even
true of the TWO compilers that due support export keyword.


You can gain by putting the implementation in a separate file. If the
class definition contains just declarations for the member functions,
it's possible to quickly look in the header file and see everthing in
the public interface in one place[*]. Hopefully it even all fits on
the screen at once. Since the public interface is all a user of the
class cares about, this can be very helpful.

The same applies to the protected interface if inheritance is involved.

Once you start putting non-trivial member function definitions in the
header, you lose this clarity.
[*] Assuming the author of the class hasn't sprinkled public, protected
and private declarations amongst each other.

Gavin Deane

Mar 7 '06 #3
Tomás wrote:
I have a few really long template functions. They belong in a source
file... and thus must be "exported".

Seeing as how few compilers support "export", could someone please point
me to a webpage/post that gives a very decent method of exploiting
"export" for those compilers that *do* export it, while still remaining
compatible with the defective compilers (which are in the majority!).

I've seen in the comp.lang.c++ FAQ that you can do:

#ifndef SUPPORT_EXPORT
#define export /* Nothing */
#endif

and so on. I works fine, but I just thought I'd check to see if there's
any better ideas before I go modifying all of my code...


One other way to do it is to implement the functionality using something
akin to void*, and then only provide type safe wrappers using templates.

I'm not sure this is generally applicable, but it works in at least some
cases. I think I read that in TC++PL, but I don't have it to hand.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Mar 7 '06 #4
Axter wrote:

However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is even
true of the TWO compilers that due support export keyword.

If your compiler supports export, or template definitions in a separate
file you can gain clarity by not mixing declarations and implementations .

You can also gain in compile times as the compiler doesn't have to check
the implementation code if it isn't required.

--
Ian Collins.
Mar 7 '06 #5
Gavin Deane wrote:
Axter wrote:

Tomás wrote:
I have a few really long template functions. They belong in a source
file... and thus must be "exported".


What make you believe they belong in a source file?

A common method to use is to put the templates in a *.hpp or *.hxx
file, and than add an include to the header at the bottom.

#ifndef FOO_H_
#define FOO_H_

template<clas s T>
class foo
{
public:
//member declartion here
};

#include "foo.hpp" //Put your long template implementation here

#endif // FOO_H_

However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is even
true of the TWO compilers that due support export keyword.



You can gain by putting the implementation in a separate file. If the
class definition contains just declarations for the member functions,
it's possible to quickly look in the header file and see everthing in
the public interface in one place[*]. Hopefully it even all fits on
the screen at once. Since the public interface is all a user of the
class cares about, this can be very helpful.


What about inlining? Don't you lose this if you put
your implementation outside of class{};?

- J.
Mar 7 '06 #6
Jacek Dziedzic posted:
Gavin Deane wrote:
Axter wrote:

Tomás wrote:

I have a few really long template functions. They belong in a source
file... and thus must be "exported".

What make you believe they belong in a source file?

A common method to use is to put the templates in a *.hpp or *.hxx
file, and than add an include to the header at the bottom.

#ifndef FOO_H_
#define FOO_H_

template<cla ss T>
class foo
{
public:
//member declartion here };

#include "foo.hpp" //Put your long template implementation here

#endif // FOO_H_

However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is eventrue of the TWO compilers that due support export keyword.

You can gain by putting the implementation in a separate file. If the
class definition contains just declarations for the member functions,
it's possible to quickly look in the header file and see everthing in
the public interface in one place[*]. Hopefully it even all fits on
the screen at once. Since the public interface is all a user of the
class cares about, this can be very helpful.


What about inlining? Don't you lose this if you put
your implementation outside of class{};?

- J.


Hence the "inline" keyword.

-Tomás
Mar 7 '06 #7

Jacek Dziedzic wrote:
Gavin Deane wrote:
Axter wrote:
However, I recommend just simplifying things, and keep the really long
template implementation inside the class declaration.
You don't gain anything by putting it in a seperate file. This is even
true of the TWO compilers that due support export keyword.


You can gain by putting the implementation in a separate file. If the
class definition contains just declarations for the member functions,
it's possible to quickly look in the header file and see everthing in
the public interface in one place[*]. Hopefully it even all fits on
the screen at once. Since the public interface is all a user of the
class cares about, this can be very helpful.


What about inlining? Don't you lose this if you put
your implementation outside of class{};?


Yes, but that's not relevant to my point. You snipped the part where I
said

<quote>
Once you start putting non-trivial member function definitions in the
header, you lose this clarity.
</quote>

The OP talked about a "really long" function. While "really long" and
"non-trivial" are not precise terms, I think they both suggest the sort
of function that is unlikely to be a good candidate for inlining.

I wasn't suggesting that function definitions should never be placed in
the header. I was pointing out a possible disadvantage - loss of
clarity - of doing so. But that disadvantage might sometimes be
outweighed by other considerations.

Gavin Deane

Mar 7 '06 #8
Tomás wrote:

You can gain by putting the implementation in a separate file. If the
class definition contains just declarations for the member functions,
it's possible to quickly look in the header file and see everthing in
the public interface in one place[*]. Hopefully it even all fits on
the screen at once. Since the public interface is all a user of the
class cares about, this can be very helpful.


What about inlining? Don't you lose this if you put
your implementation outside of class{};?

- J.


Hence the "inline" keyword.


Ah yes, I missed on the part where the "separate file"
was in fact #included in the header file. I was thinking
about the case in which definitions wind up in a separate
file that is not #included in the header and hence the
function definitions are not seen and inline cannot be used.

thanks,
- J.
Mar 7 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
29467
by: DarkSpy | last post by:
many c++ compilers including "gcc" have not implemented the "export" keyword, but the comeau compilers made it (just i knew). i want to know about: is it too difficult to implement "export" keyword? if it is, i know the history that is without "export" keyword of C++ compilers with five years (sorry about my poor english :-) ), in five years...
205
10468
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.