C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std-functions and indeterminate values

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Thomas Mang
Guest





PostPosted: Wed Dec 29, 2004 9:08 pm    Post subject: std-functions and indeterminate values Reply with quote



Hello,

Consider these fragments of code:

a)

{
int i;
std::cin >> i;
}

b)

{
char cArray[10];
std::copy(someIterator, someIterator + 10, cArray);
}


Here, both i and cArray have indeterminate value.

What I wonder is:
Is there anything that forbids std-functions (free and member) to make use
of these values other than to write?

In other words, is this pseudo-implementation (template stuff omitted) of
operator>> forbidden?

istream& istream::operator>>(int & i)
{
int someInt = i; // use of i, although probably stupid
....
}


Thank you,

Thomas



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Mark Van Peteghem
Guest





PostPosted: Sat Jan 01, 2005 1:18 am    Post subject: Re: std-functions and indeterminate values Reply with quote



Thomas Mang wrote:

Quote:
Consider these fragments of code:

a)

{
int i;
std::cin >> i;
}

b)

{
char cArray[10];
std::copy(someIterator, someIterator + 10, cArray);
}


Here, both i and cArray have indeterminate value.

What I wonder is:
Is there anything that forbids std-functions (free and member) to make use
of these values other than to write?


No, there is no way this can be done in C++, for std-functions or other
functions. I recall it is possible in C#, with the 'out' specifier, but
I don't know C# that well.

Mark dot Van dot Peteghem at q-mentum dot com
http://www.q-mentum.com -- easier and more powerful unit testing


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Thomas Mang
Guest





PostPosted: Sat Jan 01, 2005 1:21 am    Post subject: Re: std-functions and indeterminate values Reply with quote




"Thomas Mang" <nospam (AT) pop (DOT) ucsd.edu> schrieb im Newsbeitrag
news:41d29c91$0$20182$3b214f66 (AT) usenet (DOT) univie.ac.at...
Quote:

b)

{
char cArray[10];
std::copy(someIterator, someIterator + 10, cArray);
}



Please substitute the char[] by another array, e.g. a double[].
Using char[] was obviously not particularly clever for
demonstration.........


However, the point remains:

Is there anything that guarantees this doesn't yield undefined behavior?


Thomas



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Thomas Mang
Guest





PostPosted: Sat Jan 01, 2005 1:22 am    Post subject: Re: std-functions and indeterminate values Reply with quote


"Thomas Mang" <nospam (AT) pop (DOT) ucsd.edu> schrieb im Newsbeitrag
news:41d29c91$0$20182$3b214f66 (AT) usenet (DOT) univie.ac.at...
Quote:
Hello,

Consider these fragments of code:


b)

{
char cArray[10];
std::copy(someIterator, someIterator + 10, cArray);
}


Besides my other correction about char[], please forget this example
entirely. The specifications of the algorithm (output-iterator; requirements
/ complexity) seem to disallow any possible read-use of values.

However, the issue with operator>> remains.


Thomas



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.