 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Thomas Mang Guest
|
Posted: Wed Dec 29, 2004 9:08 pm Post subject: std-functions and indeterminate values |
|
|
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
|
Posted: Sat Jan 01, 2005 1:18 am Post subject: Re: std-functions and indeterminate values |
|
|
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
|
Posted: Sat Jan 01, 2005 1:21 am Post subject: Re: std-functions and indeterminate values |
|
|
"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
|
Posted: Sat Jan 01, 2005 1:22 am Post subject: Re: std-functions and indeterminate values |
|
|
"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 |
|
 |
|
|
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
|
|