Sign in to follow this  
beebs1

Order of << operator.

Recommended Posts

Hiya,

I've written a couple of wrapper classes for ODBC, and I'm using the << operator in a test application.

[code]
while(resultSet->fetchNext())
{
std::cout << "ID " << resultSet->getUInt32(1) << ", " << resultSet->getString(2) << "\n";
}
[/code]

This is causing an ODBC error, and I believe it's because the API requires me to access columns in increasing order.. column 1, column 2, etc.

I can see that the code is actually calling the get...() methods from right to left, which is the complete opposite of what I've always assumed...

Does anyone know a way of making it call from 'left to right' instead, without splitting into multiple lines?

Many thanks for any suggestions!

Share this post


Link to post
Share on other sites
The order of evaluation of subexpressions within an expression is undefined. Only between [url="http://msdn.microsoft.com/en-us/library/d45c7a5d%28v=vs.80%29.aspx"]sequence points[/url] can you guarantee order of evaluation (expressions before a sequence point are guaranteed to be evaluated any expression after a sequence point). That is, it is possible for getString(2) to be evaluated before getString(1), but don't mistake that for one being printed before the other one though; the order of what is passed through the stream is well defined and guaranteed.

There is no real way to guarantee the order of evaluation inside an expression. But what is the problem with splitting it in multiple lines?
[source]
while(resultSet->fetchNext())
{
unsigned int r1 = resultSet->getUInt32(1);
unsigned int r2 = resultSet->getUInt32(2);
std::cout << "ID " << r1 << ", " << r2 << "\n";
}

[/source]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this