Discussion:
Can I have the compiler ignore export keyword ?
(too old to reply)
Timothy Madden
2010-01-29 19:56:47 UTC
Permalink
Hello

I have Visual Studio 2008 Service Pack at work and I would like to write
my template code in a .cpp file, and only the template declarations in
the .h or .hpp file, as if export would be supported and as if I could
export my templates.

However without export support for such separation to actually work the
header file will include the .cpp file with a conditional compilation
directive like

#ifndef USE_EXPORT
# include "File.cpp"
#endif

and also, for things to work, the .cpp file should include only template
or inline functions definitions. Please don't bother too much with the
ugly idea that I include a .cpp file; the file is really meant to define
templates only and be included if necessary.

The advantage is that with export support I would then just define
USE_EXPORT for my project and all templates, already separated in .cpp
files, will no longer be bodily included and will get exported.

If you have read some things about templates a little you will find that
this is a quite known approach and that it works very nice.

However for that I would like to declare my templates with the export
keyword, and have the compiler ignore it (as other compilers do, to
support this separation model).

I see my cl already outputs a warning that export 'is not yet supported,
but reserved', but immediately after the warning I also get an error,
which is a problem.

Can I somehow get the compiler to ignore export with some options or
pragmas ?

I know I can use a define instead, that will expand to export only when
possible, but I would really like to keep my code clear, with the export
keyword as is, and rather set some project options to avoid my problem ...

Thank you,
Timothy Madden
Igor Tandetnik
2010-01-29 21:14:41 UTC
Permalink
Post by Timothy Madden
However for that I would like to declare my templates with the export
keyword, and have the compiler ignore it (as other compilers do, to
support this separation model).
I see my cl already outputs a warning that export 'is not yet
supported, but reserved', but immediately after the warning I also
get an error, which is a problem.
Can I somehow get the compiler to ignore export with some options or
pragmas ?
#define export

This is, technically, illegal - you are not supposed to #define macros whose names match language keywords. But it would work, in a pinch.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
Timothy Madden
2010-02-02 11:47:36 UTC
Permalink
Post by Igor Tandetnik
Post by Timothy Madden
However for that I would like to declare my templates with the export
keyword, and have the compiler ignore it (as other compilers do, to
support this separation model).
I see my cl already outputs a warning that export 'is not yet
supported, but reserved', but immediately after the warning I also
get an error, which is a problem.
Can I somehow get the compiler to ignore export with some options or
pragmas ?
#define export
This is, technically, illegal - you are not supposed to #define macros whose names match language keywords. But it would work, in a pinch.
In the end that is what I did.

I was wondering if the compiler has or is going to have better support
for this, though ...

Thank you,
Timothy Madden

Continue reading on narkive:
Search results for 'Can I have the compiler ignore export keyword ?' (Questions and Answers)
10
replies
What is AIX Box?
started 2006-05-08 15:58:44 UTC
hardware
Loading...