473,379 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

C++ and "flush" -- So very confused

So I have two versions of a program (these are complete programs, not
excerpts):

Version 1:
template <class T >
void foo() {
return bar( T() );
}
Version 2:
template <class T >
void foo() {
return (bar)( T() );
}
The only difference between the two is that in the second version, I
have put parentheses around bar.

GCC versions 3.4 and 4.1 and Comeau's online front end accept version 1
but reject version 2
ICC (9.1 I think), MSVC 7.1, and Sun CC accept both versions

So have a few questions:

1. There is no definition of bar. Why does it even compile at all?
(This holds true if I replace "flush" with something like "f") I guess
it's because it doesn't try to resolve the call until foo is
instantiated. Is this right?
2. Why is there a difference between the versions on GCC and Comeau?
3. What does the standard say about this? I'm guessing by #2 that it's
undefined

Evan

Dec 11 '06 #1
3 1550
Evan wrote:
So I have two versions of a program (these are complete programs, not
excerpts):
Oops, ignore the title's reference to "flush".

Originally I had a bit more complex example that was minimized from a
preprocessed file, so had names left over from the actual headers.
("foo" used to be "endl" and "bar" used to be "flush".) However, I then
figured out more about what was happening, and that it didn't depend on
the "flush" name (which for a while I was wondering if it was a
compiler builtin or something), and I figured out another way to
simplify it further, and at that point I changed it from the minimized
example to something more abstract.

But I forgot to change the title. (The "so very confused" part is even
not nearly as strong as I thought; for a while I was very confused
about why the examples compiled at all, but then I realized it must not
do name lookup on bar/flush until instantiation, and things became a
lot clearer. So now I'm more posting to ask if MSVC, ICC, and Sun are
too permissive; GCC and Comeau too restrictive (with Comeau in there --
ha!); or if the standard leaves the version 2 case undefined.

Evan

Dec 11 '06 #2
Evan :
So I have two versions of a program (these are complete programs, not
excerpts):

Version 1:
template <class T >
void foo() {
return bar( T() );
}
Version 2:
template <class T >
void foo() {
return (bar)( T() );
}
The only difference between the two is that in the second version, I
have put parentheses around bar.

GCC versions 3.4 and 4.1 and Comeau's online front end accept version 1
but reject version 2
ICC (9.1 I think), MSVC 7.1, and Sun CC accept both versions

So have a few questions:

1. There is no definition of bar. Why does it even compile at all?
(This holds true if I replace "flush" with something like "f") I guess
it's because it doesn't try to resolve the call until foo is
instantiated. Is this right?
2. Why is there a difference between the versions on GCC and Comeau?
3. What does the standard say about this? I'm guessing by #2 that it's
undefined

Evan
The function template will be initialized when it is used.
So the complier say nothing about the undifined name bar.
Dec 11 '06 #3
On 10 Dec 2006 23:50:25 -0800, "Evan" <ev****@gmail.comwrote:
>So I have two versions of a program (these are complete programs, not
excerpts):

Version 1:
template <class T >
void foo() {
return bar( T() );
-- when the template is instantiated, it will look up for
something called bar, applicable in that case (i.e. it may be applied
to an object of type T, and will return void)
}
Version 2:
template <class T >
void foo() {
return (bar)( T() );
-- you are trying to make an old-styled cast of a T object
(just created) to something of type bar, and return it, with a
return-specification of void ==error
}
The only difference between the two is that in the second version, I
have put parentheses around bar.

GCC versions 3.4 and 4.1 and Comeau's online front end accept version 1
but reject version 2
ICC (9.1 I think), MSVC 7.1, and Sun CC accept both versions

So have a few questions:

1. There is no definition of bar. Why does it even compile at all?
(This holds true if I replace "flush" with something like "f") I guess
it's because it doesn't try to resolve the call until foo is
instantiated. Is this right?
Yes
>2. Why is there a difference between the versions on GCC and Comeau?
You have the explanation above
>3. What does the standard say about this? I'm guessing by #2 that it's
undefined
Without reading directly the standard, but applying the explanation
given above, you will see clearly tat Version 2 is wrong, and veriosn
1 is OK. When in doubt, trust Comeau.

Best regards,

Zara
Dec 11 '06 #4

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

Similar topics

8
by: Jerry | last post by:
Hi All How can I produce an output to the browser and let the script continue to work in the background, producing a later screen output? Example: Trigger a database search so that the user...
2
by: Richard Morey | last post by:
Hi, I am trying to build an "in between" page to show an animated "Working.." gif while a long process runs on the server via ASP. The problem is that the table/gif is not displaying when I...
16
by: Michael | last post by:
just a quickie: as cout << endl; is to cout << "\n"; is there an equivalent for cout << "\t";
7
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. A second call to fopen doesn't create the file if it has been deleted. I would like to use fopen for its pointer return value to...
11
by: Junkguy | last post by:
I need some help programmatically causing a row in a DataGrid to "flush" its contents to its bound data (in Visual Studio 6 using Windows Forms with C#). My issue is I want to send an update to...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
2
by: Brent | last post by:
Like many sites, mine has a standard "look" -- a template, if you will -- that visitors see on each page. I've tried to keep the code and HTML separate to the extent possible, and for most standard...
5
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the...
1
by: Sharon | last post by:
Hi, I have a smarty template with about 500 rows, that take a long time to load. I was wondering if there was a way to display it by parts (i.e. first of all display the first 100 rows, then rows...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.