Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > exported templates in icpc

Reply
Thread Tools

exported templates in icpc

 
 
ciccio
Guest
Posts: n/a
 
      01-07-2008
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;
}
 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      01-07-2008
On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> wrote:
> 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]
 
Reply With Quote
 
 
 
 
ciccio
Guest
Posts: n/a
 
      01-07-2008
Salt_Peter wrote:
> On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> wrote:
>> 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
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      01-07-2008
On Jan 7, 1:33 pm, ciccio <(E-Mail Removed)> wrote:
> Salt_Peter wrote:
> > On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> wrote:


> >> 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


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).

--
James Kanze (GABI Software) (E-Mail Removed)
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      01-07-2008
On Jan 7, 7:33 am, ciccio <(E-Mail Removed)> wrote:
> Salt_Peter wrote:
> > On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> wrote:
> >> 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



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.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      01-08-2008
On Jan 7, 7:06 pm, Salt_Peter <(E-Mail Removed)> wrote:
> On Jan 7, 7:33 am, ciccio <(E-Mail Removed)> wrote:
> > Salt_Peter wrote:
> > > On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> 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.

> 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).

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique oriente objet/
Beratung in objektorientierter Datenverarbeitung
9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
ciccio
Guest
Posts: n/a
 
      01-08-2008
James Kanze wrote:
> On Jan 7, 7:06 pm, Salt_Peter <(E-Mail Removed)> wrote:
>> On Jan 7, 7:33 am, ciccio <(E-Mail Removed)> wrote:
>>> Salt_Peter wrote:
>>>> On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> 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?

> --
> James Kanze (GABI Software) email:(E-Mail Removed)
> Conseils en informatique oriente objet/
> Beratung in objektorientierter Datenverarbeitung
> 9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
jalina
Guest
Posts: n/a
 
      01-08-2008
ciccio a crit :
> James Kanze wrote:
>> On Jan 7, 7:06 pm, Salt_Peter <(E-Mail Removed)> wrote:
>>> On Jan 7, 7:33 am, ciccio <(E-Mail Removed)> wrote:
>>>> Salt_Peter wrote:
>>>>> On Jan 7, 5:11 am, ciccio <(E-Mail Removed)> 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......

>
>> --
>> James Kanze (GABI Software) email:(E-Mail Removed)
>> Conseils en informatique oriente objet/
>> Beratung in objektorientierter Datenverarbeitung
>> 9 place Smard, 78210 St.-Cyr-l'cole, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
tragomaskhalos
Guest
Posts: n/a
 
      01-08-2008
On Jan 8, 10:11*am, jalina <(E-Mail Removed)> wrote:
>
> 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++.

 
Reply With Quote
 
jalina
Guest
Posts: n/a
 
      01-08-2008
tragomaskhalos a crit :
> On Jan 8, 10:11 am, jalina <(E-Mail Removed)> wrote:
>> 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


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)

> Many people consider the absence of aforementioned controlling
> mega-corporation a point in favour of C++.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OVERNITE ACM ICPC 2009 MULTI PROVINCIAL PROGRAMMING CONTEST Biswajyoti Pal Java 0 11-10-2008 04:11 PM
OVERNITE ACM ICPC 2009 MULTI PROVINCIAL PROGRAMMING CONTEST Biswajyoti Pal C++ 0 11-10-2008 04:11 PM
templates being exported Rahul C++ 1 01-13-2008 07:31 PM
Curious template behavior, g++ and xlC and icpc ckhoge@gmail.com C++ 0 06-15-2005 01:08 AM
Some work on the ICPC problems. Jerome Lefebvre Python 0 08-21-2003 01:01 AM



Advertisments