PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > i = i++;
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
i = i++;

Réponse
 
LinkBack Outils de la discussion
Vieux 29/05/2008, 11h23   #1
rahul
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut i = i++;

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.
  Réponse avec citation
Vieux 29/05/2008, 11h40   #2
Richard Bos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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
  Réponse avec citation
Vieux 29/05/2008, 11h52   #3
Bartc
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;


"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


  Réponse avec citation
Vieux 29/05/2008, 12h17   #4
Willem
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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
  Réponse avec citation
Vieux 29/05/2008, 12h31   #5
Richard Tobin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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)
  Réponse avec citation
Vieux 29/05/2008, 12h42   #6
Barry Schwarz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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
  Réponse avec citation
Vieux 29/05/2008, 13h27   #7
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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 **
  Réponse avec citation
Vieux 29/05/2008, 15h30   #8
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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"
  Réponse avec citation
Vieux 30/05/2008, 02h56   #9
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: i = i++;

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"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h00.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17569 seconds with 17 queries