Support for export keyword ?

T

Timothy Madden

Hello

I would very much like to see the export keyword implemented and working
in my compiler, but unfortunately my company uses msvc ...

Do you currently use export to write your templates ?

What compilers do you use that support this ?
What free compilers are there that support export ?

Thank you,
Timothy Madden
 
S

Saeed Amrollahi

Hello

I would very much like to see the export keyword implemented and working
in my compiler, but unfortunately my company uses msvc ...

Do you currently use export to write your templates ?

What compilers do you use that support this ?
What free compilers are there that support export ?

Thank you,
Timothy Madden

Hi Timothy
I like to use export keyword and I use the MS VC++ too.
As far as I know there are two compilers that supports this
capability:
Edison Design Group (EDG) and Comeau C++, the second one is free, I
beleive,
but I didn't use it.
export is a relatively old feature of C++. The bad news is that,
because very few compilers implemented export so far, the C++ standard
committee
decided to remove or deprecate export at Santa Cruz meeting, October
2009.
of course, it isn't final.
If you like to know about template code organization please check out
1. The C++ Programming Language section 13.7
2. http://parashift.com/c++-faq-lite/templates.html#faq-35.[12,13,
14, 15]

Good luck
-- Saeed Amrollahi

PS. Please check the GNU g++.
 
T

Timothy Madden

Saeed said:
Hi Timothy
I like to use export keyword and I use the MS VC++ too.
As far as I know there are two compilers that supports this
capability:
Edison Design Group (EDG) and Comeau C++, the second one is free, I
beleive,
but I didn't use it.
export is a relatively old feature of C++. The bad news is that,
because very few compilers implemented export so far, the C++ standard
committee
decided to remove or deprecate export at Santa Cruz meeting, October
2009.
of course, it isn't final.
[...]

Deprecating export would be a pity, I though implementations were
implementing the standard, and not the other way around ... :(

Besides some compilers have it and it would not be fair to deprecate it.
I know Sun and Intel C++ compilers have export, and I was wondering if
anyone else is actually using export.

I hear Comeau C++ is but a didactic or pedagogic compiler, and for real
programes it generates too much code or does not have regular
optimizations, so I do not expect to hear about people that are using it.
 
R

REH

Edison Design Group (EDG) and Comeau C++, the second one is free, I
beleive,
but I didn't use it.

EDG is just a front-end, not a full compiler. It is actually the one
used by Comeau (and Intel). I don't believe Comeau is free. I think it
is around $50.

REH
 
J

Jerry Coffin

[ ... ]
Besides some compilers have it and it would not be fair to
deprecate it. I know Sun and Intel C++ compilers have export, and I
was wondering if anyone else is actually using export.

Intel uses the EDG front end, same as Comeau does. The last time I
noticed, however, the Intel compiler didn't _really_ support export.
The EDG front-end supports export, so the Intel compiler has (at
least some of) the capability, but it's undocumented and not really
supported -- nobody at Intel is going to stop you from using it, but
they're not going to give you any help if you run into a problem
either.
I hear Comeau C++ is but a didactic or pedagogic compiler, and for real
programes it generates too much code or does not have regular
optimizations, so I do not expect to hear about people that are using it.

Comeau actually produces quite reasonable code -- for some input,
it's substantially better than anything else I've found. At the same
time, no, it doesn't have all the usual optimizations. Since it
produces C source code as its output, some optimizations don't really
make a lot of sense for it. To get those kinds of optimizations, you
need to enable them in the back-end compiler you use with it. Just
for example, if you use MS VC as the back-end you can pass arguments
through to it by prefixing them with '/', where options for the
Comeau compiler itself are prefixed with '-', so something like:

como --vc71 /O2b2 /GL somefile.cpp
 
T

Timothy Madden

Juha Nieminen wrote:
[...]
Currently it's possible to "emulate" export templates in a limited way
by using manual instantiation of the locally-implemented template code
for each type used in the code. This achieves the same effect as export
templates (iow. template implementation is instantiated into its own
compilation unit, and this code has access to the local scope of that
compilation unit, ie. the nameless namespace etc). Of course it's a
limited technique because every time the template is used with a new
type you have to go and manually add an instantiation line to that
implementation file.

It would be a lot more useful if the compiler did that automatically
for me.

Indeed.

Yeah I know about the explicit instantiation approach.

It is also used to prevent the compiler form instantiating the template
for the same type arguments over and over again in each and every
translation unit that makes use of the template, just to have the linker
remove all redundant copies afterwards form the generated object files
(at link time).

That is if you have a project with 500 .cc (or .cpp) files and all of
them make use of std::vector<std::list<int>>, than for a full project
compilation the std::vector and std::list templates are instantiated 500
times (once for each .cc file) with the same type arguments, and with
some other more complicated templates instead of std::vector people may
find that the compilation time increases too much because of this.

However the copies are not necessary as all but one of them are
discarded by the linker when the final binary is linked, so for that
people may use compiler options to prevent implicit template
instantiation at all.

This way templates are only instantiated explicitly, as reported by the
linker when it sees the missing instantiations.
 
T

Timothy Madden

Jerry said:
[ ... ]
Besides some compilers have it and it would not be fair to
deprecate it. I know Sun and Intel C++ compilers have export, and I
was wondering if anyone else is actually using export.

Intel uses the EDG front end, same as Comeau does. The last time I
noticed, however, the Intel compiler didn't _really_ support export.
The EDG front-end supports export, so the Intel compiler has (at
least some of) the capability, but it's undocumented and not really
supported -- nobody at Intel is going to stop you from using it, but
they're not going to give you any help if you run into a problem
either.
Oh crap ... so Intel and Comeau are but mere C++ to C translators !

Why do people bother to even mention/talk about such pathetic excuses
for a compiler ?

So maybe Sun Studio Compiler is still standing as a /compiler/ that
implements export ?

Thank you,
Timothy Madden
 
J

Jerry Coffin

[ ... ]
Oh crap ... so Intel and Comeau are but mere C++ to C translators !

No -- Intel produces object code directly.
Why do people bother to even mention/talk about such pathetic excuses
for a compiler ?

Producing C as its output doesn't make Comeau any less a compiler
than producing object code would. Your claim only shows that you
don't know what you're talking about.

From a practical viewpoint, its use of C as an intermediate language
isn't normally visible at all. You run the compiler, and you get an
executable file as output.
So maybe Sun Studio Compiler is still standing as a /compiler/ that
implements export ?

Not likely -- especially since (as far as I can see) Sun specifically
says their most recent compiler does NOT implement export. See:

http://dlc.sun.com/pdf/820-7599/820-7599.pdf, page 228.

According to Sun: "This feature is not yet implemented, but the
export keyword is recognized."

So, people talk about Comeau and Intel as the only ones that
implement export, because nothing else implements export. They talk
about Comeau, because it's the ONLY one that really supports export.
 
T

Timothy Madden

[ ... ]
Oh crap ... so Intel and Comeau are but mere C++ to C translators !

No -- Intel produces object code directly.
Why do people bother to even mention/talk about such pathetic excuses
for a compiler ?

Producing C as its output doesn't make Comeau any less a compiler
than producing object code would. Your claim only shows that you
don't know what you're talking about.

From a practical viewpoint, its use of C as an intermediate language
isn't normally visible at all. You run the compiler, and you get an
executable file as output.
So maybe Sun Studio Compiler is still standing as a /compiler/ that
implements export ?

Not likely -- especially since (as far as I can see) Sun specifically
says their most recent compiler does NOT implement export. See:

http://dlc.sun.com/pdf/820-7599/820-7599.pdf, page 228.

According to Sun: "This feature is not yet implemented, but the
export keyword is recognized."

So, people talk about Comeau and Intel as the only ones that
implement export, because nothing else implements export. They talk
about Comeau, because it's the ONLY one that really supports export.

I well know C++ compilers are actually translators from C++ to
assembly language, but still there is a big difference between a cheap
C++ to C translator and a real C++ compiler. Big difference !

This is exactly why such a good-looking, standards-conforming pseudo
"compiler" is not really wide-spread as others, real ones, are,
despite being less conforming and more expensive :).

I would like to try Comeau but they have no free version for their
cheap translator, they actually charge money for it !

So if I just want to see the export keyword live in action I can only
try the free Linux version of Intel C++ compiler.
The Intel compiler is also awkward in that it requires Microsoft
Visual C++ or at last some SDK in order to run ! The Linux version is
somewhat better: it requires gcc ...

If only they would have a free Windows version that would work with
mingw32 gcc, that would be so cool !

I am still to try it, to see the export keyword actually working.

You are right about Sun Studio compiler, it merely recognises export
as a C++ keyword, but does not implement the feature. I was looking
through their online documentation too briefly to notice that a simple
mention of the keyword does not mean the compiler supports exporting
templates ...
 
D

Dilip

Hi Timothy
I like to use export keyword and I use the MS VC++ too.
As far as I know there are two compilers that supports this
capability:
Edison Design Group (EDG) and Comeau C++, the second one is free, I
beleive,
but I didn't use it.
export is a relatively old feature of C++. The bad news is that,
because very few compilers implemented export so far, the C++ standard
committee
decided to remove or deprecate export at Santa Cruz meeting, October
2009.
of course, it isn't final.

[...]

Deprecating export would be a pity, I though implementations were
implementing the standard, and not the other way around ... :(

If you have the patience you can read through this monster thread
starting here:
http://groups.google.com/group/comp.lang.c++.moderated/msg/26f44cf244d2789c

that discussed this very topic. You will see, compiler writers aren't
exactly enthusiastic about implementing export.
 
I

Ian Collins

Timothy said:
I well know C++ compilers are actually translators from C++ to
assembly language, but still there is a big difference between a cheap
C++ to C translator and a real C++ compiler. Big difference !

Maybe there is, but Comeau is a good one.

If I want a good C++ compiler for a platform with a native C compiler
but without a C++ one, I know where to go.
 
T

Timothy Madden

Saeed said:
Hello
I would very much like to see the export keyword implemented and working
in my compiler, but unfortunately my company uses msvc ...
Do you currently use export to write your templates ?
What compilers do you use that support this ?
What free compilers are there that support export ?
Thank you,
Timothy Madden
Hi Timothy
I like to use export keyword and I use the MS VC++ too.
As far as I know there are two compilers that supports this
capability:
Edison Design Group (EDG) and Comeau C++, the second one is free, I
beleive,
but I didn't use it.
export is a relatively old feature of C++. The bad news is that,
because very few compilers implemented export so far, the C++ standard
committee
decided to remove or deprecate export at Santa Cruz meeting, October
2009.
of course, it isn't final.

Deprecating export would be a pity, I though implementations were
implementing the standard, and not the other way around ... :(

If you have the patience you can read through this monster thread
starting here:http://groups.google.com/group/comp.lang.c++.moderated/msg/26f44cf244...

that discussed this very topic.  You will see, compiler writers aren't
exactly enthusiastic about implementing export.

Thank you.
I will look through it when I have the time.

I do not understand what is the big deal with implementing export.
Compiler writers can already instantiante templates on demand, within
the same source
file without export, all they need is to save the internal template
definition (the
parsed reprezentation of the template source) they alread use, at the
time the template
definition is seen in the source code, and then load it back later in
a final instantiation
step in the build system, to compile them into instances. I know
things are more
complicated under the hood, but the whole export thing is very, very
possible to implement.

Thank you,
Timothy Madden
 
J

James Kanze

[ ... ]
Oh crap ... so Intel and Comeau are but mere C++ to C translators !
No -- Intel produces object code directly.

That would surprise me. Every compiler today uses several
phases, the first of which parses and translates the code to an
intermediate representation.

[...]
I well know C++ compilers are actually translators from C++ to
assembly language, but still there is a big difference between
a cheap C++ to C translator and a real C++ compiler. Big
difference !

None at all. As Ian said, you obviously don't know what you're
talking about. All compilers today (and ever since I can
remember) divide compilation into several phases. The first
phase (the front end) generates an intermediate code which the
following stages can use. In the case of EDG (the ones who've
actually implemented export), the front-end is designed so that
it can feed any one of a number of back-ends (and can easily be
adapted to other back-ends). Using C as an intermediate lanuage
simply means that you have a wide choice of compatible back-ends
readily available---it doesn't change anything with regards to
the quality of the front end. (One could almost say that C was
designed with this in mind. A portable assembler.)

And the EDG front end is without a doubt the best front end
currently available. Configure it to generate C, and add a high
quality C compiler as the back end, and you have one of the best
C++ compilers around.
This is exactly why such a good-looking, standards-conforming
pseudo "compiler" is not really wide-spread as others, real
ones, are, despite being less conforming and more expensive
:).

The reason Comeau isn't more widespread is purely commercial.
Their commercial budget is significantly less than that of
Microsoft or Sun. And of course, there are significant
advantages of using the "native" compiler: Sun CC under Solaris,
Microsoft under Windows, etc.

[...]
If only they would have a free Windows version that would work with
mingw32 gcc, that would be so cool !

Writing and maintaining a compiler is a lot of work. Some
people like to get paid for their work.
 
J

James Kanze

[...]
I do not understand what is the big deal with implementing
export. Compiler writers can already instantiante templates
on demand, within the same source file without export, all
they need is to save the internal template definition (the
parsed reprezentation of the template source) they alread use,
at the time the template definition is seen in the source
code, and then load it back later in a final instantiation
step in the build system, to compile them into instances. I
know things are more complicated under the hood, but the whole
export thing is very, very possible to implement.

Possible, yes---the proof is that it has already been done.
It's still fairly difficult, and interacts with the usual
separation of compilation and link rather seriously (if done
well, at least). To instantiate a template at link time, you
need to reconstitute the environment of the point of
instantiation, which isn't necessarily trivial.

Also, of course, the semantics of an exported template aren't
the same as those of a template which isn't exported. Many
cases of undefined behavior with todays templates are well
defined if the template is exported.
 
B

Bo Persson

Pete said:
It took EDG about a year, pretty much full time for all their
staff, to implement export.

About three people at the time? .-)

Other companies, that claim they absolutely cannot afford this, have
instead been able to design and implement several entirely new
languages instead.

I don't think that shows a real lack of resources.



Bo Persson
 
B

Brian

[ ... ]
Oh crap ... so Intel and Comeau are but mere C++ to C translators !
No -- Intel produces object code directly.

That would surprise me.  Every compiler today uses several
phases, the first of which parses and translates the code to an
intermediate representation.

    [...]
I well know C++ compilers are actually translators from C++ to
assembly language, but still there is a big difference between
a cheap C++ to C translator and a real C++ compiler. Big
difference !

None at all.  As Ian said, you obviously don't know what you're
talking about.  All compilers today (and ever since I can
remember) divide compilation into several phases.  The first
phase (the front end) generates an intermediate code which the
following stages can use.  In the case of EDG (the ones who've
actually implemented export), the front-end is designed so that
it can feed any one of a number of back-ends (and can easily be
adapted to other back-ends).  Using C as an intermediate lanuage
simply means that you have a wide choice of compatible back-ends
readily available---it doesn't change anything with regards to
the quality of the front end.  (One could almost say that C was
designed with this in mind.  A portable assembler.)

And the EDG front end is without a doubt the best front end
currently available.  Configure it to generate C, and add a high
quality C compiler as the back end, and you have one of the best
C++ compilers around.
This is exactly why such a good-looking, standards-conforming
pseudo "compiler" is not really wide-spread as others, real
ones, are, despite being less conforming and more expensive
:).

The reason Comeau isn't more widespread is purely commercial.
Their commercial budget is significantly less than that of
Microsoft or Sun.  And of course, there are significant
advantages of using the "native" compiler: Sun CC under Solaris,
Microsoft under Windows, etc.

    [...]
If only they would have a free Windows version that would work with
mingw32 gcc, that would be so cool !

Writing and maintaining a compiler is a lot of work.  Some
people like to get paid for their work.

Same for a search engine and yet they don't cost money to use.
An on line C++ compiler might work, but I don't think it
should try to return/generate object code. It could generate
C or preferably a subset of C++. I've said for a number of
years that an on line compiler is the only way I know of to
make new C++ functionality available to people in any sort
of reasonable time frame.


Brian Wood
http://webEbenezer.net
(651) 251-9384
 
J

Jerry Coffin

[ ... ]
That would surprise me. Every compiler today uses several
phases, the first of which parses and translates the code to an
intermediate representation.

Yes, in this case, "directly" just means you'd have to work _really_
hard to get at/see the intermediate code (e.g. run the compiler under
a debugger, and decipher the intermediate code from a dump of
memory...)

[ ... ]
None at all. As Ian said, you obviously don't know what you're
talking about.

Actually, I'm the one who said that -- Ian may have implied the same,
but he's more polite than I am! :)
All compilers today (and ever since I can
remember) divide compilation into several phases.

Generally it's going the other direction -- at one time, compilers
used far _more_ passes (phases, if you prefer) simply due to memory
limitations. I've never seen it confirmed, but according to rumor one
of the early PL/I compilers reputedly used over 100 passes...

[ ... ]
And the EDG front end is without a doubt the best front end
currently available. Configure it to generate C, and add a high
quality C compiler as the back end, and you have one of the best
C++ compilers around.

As I understand it, you don't really have to configure it to generate
C -- that's what it generates by default. The C generator
demonstrates the hooks you use to generate other output. From what
I've read, EDG's license with Comeau _may_ preclude others from
selling versions that only generate C as output though (not certain
of that, but one old newsgroup post from one of the EDG guys gave
that impression). At most that's purely a licensing situation though
-- there's certainly no technical reason anybody else couldn't do it.

I would note, however, that there's a bit more to implementing export
than just getting the front-end right. Comeau also uses a pre-linker
that (among other things) detects whether an object file contains all
the necessary instantiations of an exported template, and re-runs the
compiler to produce others of needed. The front-end _does_, however,
implement the two-phase name lookup, which is the hard part.

The bottom line is that Comeau themselves (himself, mostly) does make
a real contribution to this -- it's not just a matter of compiling
the EDG front end and selling the result.
 
J

James Kanze

[ ... ]
That would surprise me. Every compiler today uses several
phases, the first of which parses and translates the code to an
intermediate representation.
Yes, in this case, "directly" just means you'd have to work
_really_ hard to get at/see the intermediate code (e.g. run
the compiler under a debugger, and decipher the intermediate
code from a dump of memory...)

Yes and no. The intermediate code is generally not that hard to
get at. The only difference is that generally, if it's not C,
it's not text at all, so you'd need some sort of special program
to read it.
[ ... ]
All compilers today (and ever since I can
remember) divide compilation into several phases.
Generally it's going the other direction -- at one time,
compilers used far _more_ passes (phases, if you prefer)
simply due to memory limitations. I've never seen it
confirmed, but according to rumor one of the early PL/I
compilers reputedly used over 100 passes...

There are swings. I remember a PL/I compiler that ran in 16 KB.
And took three or four hours to compile a 200 line program. But
I think it still only did two passes: what made it slow was that
just about every distinct operation in each pass was in a
separate overload (loaded from disk), and it kept almost all of
its data structures (parse tree, symbol table, etc.) on disk.

Today, I suppose that it would be entirely possible to do
everything on the fly, generating the intermediate
representation of each function in memory, then invoking the
back-end on it, before continuing to the next function. I don't
know of any compiler which actually does this (but some do
maintain the intermediate representation, or some variant of it,
until link time).

Anyhow, for those not familiar with compiler technology, the
"classical" compiler uses four passes: a front-end (which
creates the intermediate representation), an optional optimizing
pass (sometimes called the middle-end, for mostly machine
independent optimizations, like common sub-expression merging
and hoisting invariants out of loops), a back-end which
generates machine code, and an optional peep-hole optimizer
which does low level optimizations. The original C compiler
added a preprocessor, and generated assembler, rather than an
object file, both of which added a pass, but it skipped the
optimization passes. Modern C++ compilers will probably be
closer to the classical model, merging the preprocessor with the
front-end, and going directly from the intermediate
representation to object format, rather than assembler. The
better ones, of course, will defer object code generation and
most of the optimization to link time.
[ ... ]
And the EDG front end is without a doubt the best front end
currently available. Configure it to generate C, and add a high
quality C compiler as the back end, and you have one of the best
C++ compilers around.
As I understand it, you don't really have to configure it to
generate C -- that's what it generates by default. The C
generator demonstrates the hooks you use to generate other
output. From what I've read, EDG's license with Comeau _may_
preclude others from selling versions that only generate C as
output though (not certain of that, but one old newsgroup post
from one of the EDG guys gave that impression). At most that's
purely a licensing situation though -- there's certainly no
technical reason anybody else couldn't do it.

As I understand it (but I could easily be wrong), the EDG
front-end doesn't do anything by default. You have to configure
it specifically. EDG doesn't sell compilers to people like you
and me; they sell front-ends to people who will provide their
custom back-end, plus additional packaging.
I would note, however, that there's a bit more to implementing
export than just getting the front-end right.

This is something I've often wondered about. Doing export
correctly would seem to involve more than the front end.
Comeau also uses a pre-linker that (among other things)
detects whether an object file contains all the necessary
instantiations of an exported template, and re-runs the
compiler to produce others of needed. The front-end _does_,
however, implement the two-phase name lookup, which is the
hard part.
The bottom line is that Comeau themselves (himself, mostly)
does make a real contribution to this -- it's not just a
matter of compiling the EDG front end and selling the result.

Agreed. EDG does all of the really hard bits, but Comeau still
has a fair amount of work to do. An awful lot, if you consider
that it's basically a one man firm. Greg Comeau certainly earns
every penny he makes off the compiler.
 
J

James Kanze

James Kanze wrote:
It took EDG about a year, pretty much full time for all their
staff, to implement export.

I believe it was only one of their staff. And the first time's
always that hardest. Of course, who's doing it makes a
difference, and other companies likely don't have people at the
same level as EDG's. But most companies can probably afford to
put more people on it: EDG only had three developers when they
implemented it.

It's not easy, or at least, it's not easy to do well. But it's
well within the resources available to a company like Microsoft.
 
J

James Kanze

Could you give some examples of the difficulties which pop up
with that?

Could you explain to me why you think it is so simple.
One would think that it wouldn't be so much different as when
the programmer does the same thing "manually".

The programmer never does the same thing manually. To do so
would be too difficult.
In other words, when the programmer/linker sees that a
template is instantiated with type X, the programmer/linker
goes to the source file where the template is defined and adds
an explicit instantiation of it for X and then recompiles that
one object file, and that's about it.

Except that the results won't compile.

CFront actually used something like that. They noted the header
file in which the type X was defined, and grabbed that. The
problem is that it isn't enough. That header file could depend
on earlier includes, or even definitions in the main source file
or preprocessor definitions on the command line. And the
template instantiation may (and sometimes does, even in well
written code) depend on things defined later in the source file;
a classical example would be instantiating ostream_iterator over a
type which doesn't define operator<< in its header file.
It just sounds like all the linker needs is to call the
compiler to compile the necessary object file, telling the
compiler "and instantiate this template for X". Then the
compiler does that, and the linker proceeds with the new
object file as normal.

Been there, done that. I've used CFront, and there are serious
problems with this solution.
(Of course this ties the linker tightly to the compiler,
removing their current separation and independence, but... who
actually uses this separation nowadays, really? Most compilers
are also their own linkers at the same time.)

Except g++, of course. And Comeau, and Intel (I think).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top