exported templates in icpc

C

ciccio

Hi all,

The intel c++ compiler supports exported templates but I was wondering a
bit about their used syntax. If I compare the syntax written in
strostroup's book then there is a difference. So I was wondering if the
following syntax proposed by intel is correct.

Thanks a lot


// file1.cpp
#include <stdio.h>
static void trace() { printf("File 1\n"); }
export template<class T> T const& min(T const&, T const&);
int main() {
trace();
return min(2, 3);
}
// file2.cpp
#include <stdio.h>
static void trace() { printf("File 2\n"); }
export template<class T> T const& min(T const &a, T const &b) {
trace();
return a<b? a: b;
}
 
S

Salt_Peter

Hi all,

The intel c++ compiler supports exported templates but I was wondering a
bit about their used syntax. If I compare the syntax written in
strostroup's book then there is a difference. So I was wondering if the
following syntax proposed by intel is correct.

Thanks a lot

// file1.cpp
#include <stdio.h>
static void trace() { printf("File 1\n"); }
export template<class T> T const& min(T const&, T const&);
int main() {
trace();
return min(2, 3);}

// file2.cpp
#include <stdio.h>
static void trace() { printf("File 2\n"); }
export template<class T> T const& min(T const &a, T const &b) {
trace();
return a<b? a: b;

}


Did you check with Intel first?
This newsgroup doesn't cover specific compilers.
[OT]
The syntax looks correct, you do need the -export/-export_dir options.
[/OT]
 
C

ciccio

Salt_Peter said:
Hi all,

The intel c++ compiler supports exported templates but I was wondering a
bit about their used syntax. If I compare the syntax written in
strostroup's book then there is a difference. So I was wondering if the
following syntax proposed by intel is correct.

Thanks a lot

// file1.cpp
#include <stdio.h>
static void trace() { printf("File 1\n"); }
export template<class T> T const& min(T const&, T const&);
int main() {
trace();
return min(2, 3);}

// file2.cpp
#include <stdio.h>
static void trace() { printf("File 2\n"); }
export template<class T> T const& min(T const &a, T const &b) {
trace();
return a<b? a: b;

}


Did you check with Intel first?
This newsgroup doesn't cover specific compilers.
[OT]
The syntax looks correct, you do need the -export/-export_dir options.
[/OT]

Yes I am aware of that, but according to strostroup there should not be
an export in file1.cpp. So the question was, is the syntax correct?
Hence, it belongs in this news group ;-)
 
J

James Kanze

Did you check with Intel first?
This newsgroup doesn't cover specific compilers.
[OT]
The syntax looks correct, you do need the -export/-export_dir options.
[/OT]
Yes I am aware of that, but according to strostroup there
should not be an export in file1.cpp. So the question was, is
the syntax correct? Hence, it belongs in this news group ;-)

I seem to recall that the wording finally adopted into the
standard didn't actually correspond to the intent. I think the
code you show corresponds to the intent---it seems logical,
anyway. Stroustrup probably wrote his book before having an
actual implementation at hand, and based himself soley on the
text in the standard.

Your code is conform with the latest draft. What Stroustrup
seems to be saying corresponds to the text in C++98 (which says
that "A template shall be exported only once in a program", and
that the definition must be exported).
 
S

Salt_Peter

Did you check with Intel first?
This newsgroup doesn't cover specific compilers.
[OT]
The syntax looks correct, you do need the -export/-export_dir options.
[/OT]

Yes I am aware of that, but according to strostroup there should not be
an export in file1.cpp. So the question was, is the syntax correct?
Hence, it belongs in this news group ;-)


standard says:
An exported template need only be declared (not neccessarily defined)
in a translation unit in which it is instantiated.
....
An *implementation* may require that a translation unit containing the
definition of an exported template be compiled before any translation
unit containing an instantiation of that template.

And mostly because of that last sentence, you want to check with Intel
first.
 
J

James Kanze

[...]
standard says:

In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.
An exported template need only be declared (not neccessarily defined)
in a translation unit in which it is instantiated.
...
An *implementation* may require that a translation unit containing the
definition of an exported template be compiled before any translation
unit containing an instantiation of that template.

None of that addresses the original posters question: where do
you put the keyword "export". Basically C++98 said that it
should appear on at most one declaration in program, and that
that declaration must be in the translation unit where the
template is defined. Which means that you don't use "export" in
a header---and that the compiler doesn't know whether a template
is exported or not when it instantiates it. C++03 basically
says that a template must be declared "export" in every
translation unit in which it might be instantiated.
And mostly because of that last sentence, you want to check
with Intel first.

That last sentence is nothing but bla-bla, and doesn't mean
anything. The standard doesn't address the mechanics of how you
invoke the compiler, and a compiler is perfectly free to require
all of the source code to be available when compiling. (Quality
of implementation, of course, makes additional requirements.)
Basically, anytime you move to a new development environment,
you have to start by carefully reading the documentation, to
find out which options you want, but also any restrictions on
file organisation (particularly when templates are used).
 
C

ciccio

James said:
Salt_Peter wrote:
On Jan 7, 5:11 am, ciccio <[email protected]> wrote:
[...]
standard says:

In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.

Is there a place where I can get my hands on these standards?
 
J

jalina

ciccio a écrit :
Is there a place where I can get my hands on these standards?

I think that if you want the C/C++ standard (any version) you have to
pay (unlike many other languages including C# and Java). C++ is not a
community friendly language.

I wonder gcc is GPL so how do the guys working on g++ handle this ? Just
wondering......
 
T

tragomaskhalos

I think that if you want the C/C++ standard (any version) you have to
pay (unlike many other languages including C# and Java). C++ is not a
community friendly language.

Has it occurred to you that perhaps the reason one has to pay for the
C++ standard is that a lot of very clever people put a lot of hard
work into producing it without a single mega-corporation bankrolling
them, unlike the case with C# and Java (although the term "standard"
is AFAIK inapplicable to Java)?
Many people consider the absence of aforementioned controlling
mega-corporation a point in favour of C++.
 
J

jalina

tragomaskhalos a écrit :
Has it occurred to you that perhaps the reason one has to pay for the
C++ standard is that a lot of very clever people put a lot of hard
work into producing it without a single mega-corporation bankrolling
them, unlike the case with C# and Java

Yes you are right, not one, but many. Most of people working on the
standard are from large companies - AT&T, Sun Microsystems, IBM, HP, TI,
Microsoft, Apple, Siemens, Intel, Motorola, Data General, Merrill Lynch,
Boeing.... And I doubt that they work during their free time on the
standard.

For me it means that C++ standard is not made by individuals but by
companies.

(although the term "standard"
is AFAIK inapplicable to Java)?

In my mind, standard does not mean it has been approved by one or
another organization (backup by one or another company)

Java failed to be approved by any organization for political reasons,
nevertheless the specification is a standard de facto (and can be
downloaded freely at http://java.sun.com/docs/books/jls)
 
E

Erik Wikström

ciccio a écrit :
James said:
Salt_Peter wrote:
[...]
standard says:
In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.

Is there a place where I can get my hands on these standards?

I think that if you want the C/C++ standard (any version) you have to
pay (unlike many other languages including C# and Java). C++ is not a
community friendly language.

I wonder gcc is GPL so how do the guys working on g++ handle this ? Just
wondering......

Perhaps they buy a copy of the standard. I do not see what gcc being GPL
have anything to to with it.

BTW: Please do not quote signatures (that means you too ciccio).
 
E

Erik Wikström

James said:
Salt_Peter wrote:
[...]
standard says:

In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.

Is there a place where I can get my hands on these standards?

You can buy them from iso.org, but I think it is cheaper to buy the ANSI
versions (they are ANSI standards too). Or you can get a draft of them
that lies as close in time as possible to the date they were
standardised (from http://www.open-std.org). You can also check with any
local standardisation organisations.
 
P

Pete Becker

Yes you are right, not one, but many. Most of people working on the
standard are from large companies - AT&T, Sun Microsystems, IBM, HP,
TI, Microsoft, Apple, Siemens, Intel, Motorola, Data General, Merrill
Lynch, Boeing.... And I doubt that they work during their free time on
the standard.

For me it means that C++ standard is not made by individuals but by companies.

(although the term "standard"

In my mind, standard does not mean it has been approved by one or
another organization (backup by one or another company)

Java failed to be approved by any organization for political reasons,
nevertheless the specification is a standard de facto (and can be
downloaded freely at http://java.sun.com/docs/books/jls)

Fascinating. You don't like the C++ standard because it's "not made by
individuals but by companies", but you like the Java standard which was
made by (gasp!) a company!

The "political reasons" that Java has not been standardized by any of
the traditional standards organizations is that Sun refused to allow it.
 
R

red floyd

Erik said:
James said:
Salt_Peter wrote:
[...]
standard says:
In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.
Is there a place where I can get my hands on these standards?

You can buy them from iso.org, but I think it is cheaper to buy the ANSI
versions (they are ANSI standards too). Or you can get a draft of them
that lies as close in time as possible to the date they were
standardised (from http://www.open-std.org). You can also check with any
local standardisation organisations.

The Dead Tree BSI version is about $65 from Amazon/BN.

http://www.amazon.com/obidos/dp/0470846747
http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ISBN=0470846747
 
J

James Kanze

ciccio a écrit :
James Kanze wrote:
Salt_Peter wrote:
[...]
standard says:
In this case, you'll have to say which version. C++98 said one
thing, C++03 says another. In this case, what was actually
written in C++98 wasn't what the authors intended to say (and
described something that doesn't really make sense, and probably
isn't implementable). The wording was corrected in C++03.
Is there a place where I can get my hands on these standards?
I think that if you want the C/C++ standard (any version)
you have to pay (unlike many other languages including C#
and Java). C++ is not a community friendly language.
I wonder gcc is GPL so how do the guys working on g++ handle
this ? Just wondering......
Perhaps they buy a copy of the standard.

They might. It's certainly not expensive today. (It used to
be. I paid well over $100 for my copy of the C90 standard.) On
the other hand, people actually working on the standard
(accredited "technical experts" of the national bodies of ISO)
have access to the internal documents, which includes the
standard, and I suspect that most of the people working on g++
are also "technical experts" somewhere, or are connected with
the standard body in some way or another, and have access to the
internal documents as well.

FWIW: the money from the sale of the standard goes to ISO and
the national bodies, and is used to support the organizations.
The actual standard is written by volenteer effort. But
organizations do need money to operate as well, and IMHO, ISO
plays an important role in preventing any one organization from
"hijacking" the standard. Sun, for example, wanted to make Java
an ISO standard until they realized that this meant that they'd
actually have to listen to other people's opinions, rather than
doing whatever they felt like.
 
J

jalina

Pete Becker a écrit :
Fascinating. You don't like the C++ standard

Who did say that ? Because I make some remarks concerning the C++
standard does not mean I like it or don't like it. Please do not tell
thinks *I* like or don't like (so if I say "I can not see the moon
tonight" obviously I don't like the moon. Gosh)

I talk about java because this is the other language I play with and I
like apart from the C++.

because it's "not made by
individuals but by companies", but you like the Java standard which was
made by (gasp!) a company!

The "political reasons" that Java has not been standardized by any of
the traditional standards organizations is that Sun refused to allow it.
Sun tried to get certified the java language. See many articles (the
first I found googling:
http://www.windowsitpro.com/Article/ArticleID/17419/17419.html) ant I
remember reading a lot about it.
 
J

James Kanze

tragomaskhalos a écrit :
Yes you are right, not one, but many. Most of people working
on the standard are from large companies - AT&T, Sun
Microsystems, IBM, HP, TI, Microsoft, Apple, Siemens, Intel,
Motorola, Data General, Merrill Lynch, Boeing.... And I doubt
that they work during their free time on the standard.
For me it means that C++ standard is not made by individuals
but by companies.

Technically, the C++ standard is "made" by the national bodies
contributing to ISO: ANSI, BSI, AFNOR, DIN... Practically, it's
made by a lot of individuals working together. Some are
supported by their companies, others not. And some of the
companies contributing the most are not monsters: you'll
regularly find 100% of the technical staff of EDG or Dinkumware
at a meeting. There are also people from Boost and from g++.
In my mind, standard does not mean it has been approved by one
or another organization (backup by one or another company)

Legally, it does, at least in some countries. The important
point here is, however, that the final decision rests in some
independent organization: it's not a specification of what one
particular company does, but a standard established
independently of what one particular company might decide.
Java failed to be approved by any organization for political
reasons, nevertheless the specification is a standard de facto
(and can be downloaded freely
athttp://java.sun.com/docs/books/jls)

It's specification, not a standard. Sun wanted it to be a
standard, but withdrew it (at least from ISO) because to make it
a standard, they would have to take opinions of others into
account. (Obviously, it's not all black and white: an ECMA
standard may involve more control by a single company than an
ISO standard, and Sun's process for Java is more open than, say,
that used to establish the original Windows API. But there is a
very definite line between the final decisions being made by an
independent organization, even with intensive collaboration from
a company, and the final decisions being made by a single
company, even if it does consult with other companies or
organizations.)
 
P

Pete Becker

Sun tried to get certified the java language. See many articles (the
first I found googling:
http://www.windowsitpro.com/Article/ArticleID/17419/17419.html) ant I
remember reading a lot about it.

Sun tried to get ISO to rubberstamp Sun's version of a Java standard.
That's not what standards organizations do.

Sun also started out supporting ECMA's standardization effort for Java,
then at the first formal meeting, withdrew their support, leaving a
dozen attendees (including me) stuck in Raleigh/Durham with nothing to
do. (Literally stuck: eighteen inches of snow overnight, all
transportation shut down)

Neither of these can be accurately characterized as "failed for
political reasons." Both were the result of Sun wanting to have the
imprimatur of a standard but not wanting to go through a real
standardization process.
 
R

red floyd

Pete said:
Sun tried to get ISO to rubberstamp Sun's version of a Java standard.
That's not what standards organizations do.

Now if only someone would explain that to Microsoft
(*cough*MS-OOXML*cough*).
 
J

jalina

Pete Becker a écrit :
Sun tried to get ISO to rubberstamp Sun's version of a Java standard.
That's not what standards organizations do.

Sun also started out supporting ECMA's standardization effort for Java,
then at the first formal meeting, withdrew their support, leaving a
dozen attendees (including me

I now understand your answers to my remarks when talking about Java (he
he, ECMA loves Microsoft)

) stuck in Raleigh/Durham with nothing to
do. (Literally stuck: eighteen inches of snow overnight, all
transportation shut down)

Neither of these can be accurately characterized as "failed for
political reasons." Both were the result of Sun wanting to have the
imprimatur of a standard but not wanting to go through a real
standardization process.
So the policy of Sun, according to you, is not going through a real
standardization process. I said Java was not "standardized" for
political reasons. You just confirm my sayings, thanks (whether it is
Sun's fault or others, I am not interested)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top