|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
int i = 0;
i = i++; I noticed that some people say this is undefined as the value of a variable can not be accessed twice between two sequence points. But I think the standard says that a variable can not be modified twice between two sequence points. And in this case, it is modified just once. So, a = a++ + a++; is undefined but not i = i++. Correct me if I am wrong as I don't own a copy of the standards. I read this stuff in some book. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
rahul <rahulsinner@gmail.com> wrote:
> int i = 0; > i = i++; > I noticed that some people say this is undefined as the value of a > variable can not be accessed twice between two sequence points. > But I think the standard says that a variable can not be modified > twice between two sequence points. And in this case, it is modified > just once. So, > a = a++ + a++; > is undefined but not i = i++. > Correct me if I am wrong You're wrong. > as I don't own a copy of the standards. That, too, is wrong. Download the latest draft (of the full Standard plus the last TC); do a websearch for n1256.pdf. > I read this stuff in some book. Read the FAQ instead. Start at section 3: <http://c-faq.com/expr/index.html>. Richard |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"rahul" <rahulsinner@gmail.com> wrote in message news:4d56b949-d4e5-40e4-a4b8-029408b25c40@u36g2000prf.googlegroups.com... > int i = 0; > i = i++; > I noticed that some people say this is undefined as the value of a > variable can not be accessed twice between two sequence points. > But I think the standard says that a variable can not be modified > twice between two sequence points. And in this case, it is modified > just once. So, > a = a++ + a++; > is undefined but not i = i++. > Correct me if I am wrong as I don't own a copy of the standards. Clearly the variable i is modified twice: once to increment it, and again to assign to it (not necessarily in that order). -- Bartc |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Bartc wrote:
) ) "rahul" <rahulsinner@gmail.com> wrote in message ) news:4d56b949-d4e5-40e4-a4b8-029408b25c40@u36g2000prf.googlegroups.com... )> int i = 0; )> i = i++; )> I noticed that some people say this is undefined as the value of a )> variable can not be accessed twice between two sequence points. )> But I think the standard says that a variable can not be modified )> twice between two sequence points. And in this case, it is modified )> just once. So, )> a = a++ + a++; )> is undefined but not i = i++. )> Correct me if I am wrong as I don't own a copy of the standards. ) ) Clearly the variable i is modified twice: once to increment it, and again to ) assign to it (not necessarily in that order). But, j = i + i++; is also undefined AFAIK. SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
In article <slrng3t45u.2166.willem@snail.stack.nl>,
Willem <willem@stack.nl> wrote: >)> a = a++ + a++; >)> is undefined but not i = i++. >)> Correct me if I am wrong as I don't own a copy of the standards. >) Clearly the variable i is modified twice: once to increment it, and again to >) assign to it (not necessarily in that order). >But, j = i + i++; is also undefined AFAIK. Yes, there are two rules: Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored. "j = i + i++" violates the second one. i is read both to determine the new value of i in the second operand of +, and to determine the value of the first operand. -- Richard -- In the selection of the two characters immediately succeeding the numeral 9, consideration shall be given to their replacement by the graphics 10 and 11 to facilitate the adoption of the code in the sterling monetary area. (X3.4-1963) |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Thu, 29 May 2008 03:23:25 -0700 (PDT), rahul
<rahulsinner@gmail.com> wrote: >int i = 0; >i = i++; >I noticed that some people say this is undefined as the value of a >variable can not be accessed twice between two sequence points. >But I think the standard says that a variable can not be modified >twice between two sequence points. And in this case, it is modified >just once. So, >a = a++ + a++; >is undefined but not i = i++. >Correct me if I am wrong as I don't own a copy of the standards. I >read this stuff in some book. You are wrong on several levels. Your code modifies i more than once so even with your incomplete understanding of the restriction you should be able to see it is undefined. Don't guess what the standard says. There are numerous draft copies available for download (google for n1124 as an example). Or you could look through the google archives of this group to see the hundreds of times it has been addressed before. If your book doesn't give you the complete restriction, throw it away and look through the archives of this group for book recommendations. Remove del for email |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
rahul wrote:
> > int i = 0; > i = i++; > I noticed that some people say this is undefined as the value of a > variable can not be accessed twice between two sequence points. > But I think the standard says that a variable can not be modified > twice between two sequence points. And in this case, it is modified > just once. So, > a = a++ + a++; > is undefined but not i = i++. > Correct me if I am wrong as I don't own a copy of the standards. I > read this stuff in some book. You can get quite adequate C standard copies over the net. See the things marked "C99" below. The text version is the smallest, and I consider handiest. -- Some useful references about C: <http://www.ungerhu.com/jxh/clc.welcome.txt> <http://c-faq.com/> (C-faq) <http://benpfaff.org/writings/clc/off-topic.html> <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99) <http://cbfalconer.home.att.net/download/n869_txt.bz2> (C99, txt) <http://www.dinkumware.com/c99.aspx> (C-library} <http://gcc.gnu.org/onlinedocs/> (GNU docs) <http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction> ** Posted from http://www.teranews.com ** |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Barry Schwarz <schwarzb@dqel.com> writes:
[...] > Don't guess what the standard says. There are numerous draft copies > available for download (google for n1124 as an example). [...] n1256 is better. http://www.open-std.org/jtc1/sc22/wg...docs/n1256.pdf -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
CBFalconer <cbfalconer@yahoo.com> writes:
[...] > You can get quite adequate C standard copies over the net. See the > things marked "C99" below. The text version is the smallest, and I > consider handiest. The text version is also a pre-standard draft of C99, and differs in some (mostly minor, I think) ways from the actual standard. If you don't mind dealing with PDF rather than plain text, I recommend n1256.pdf. I'd suggest n869.txt (or rather n869_txt.bz2) only if you have serious problems with PDF documents. > -- > Some useful references about C: > <http://www.ungerhu.com/jxh/clc.welcome.txt> > <http://c-faq.com/> (C-faq) > <http://benpfaff.org/writings/clc/off-topic.html> > <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99) > <http://cbfalconer.home.att.net/download/n869_txt.bz2> (C99, txt) > <http://www.dinkumware.com/c99.aspx> (C-library} > <http://gcc.gnu.org/onlinedocs/> (GNU docs) > <http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction> -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
|
![]() |
| Outils de la discussion | |
|
|