[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: i = i++
On Wed, Jan 10, 2001, the greycells of P k j ~ c K expressed:
> read some C faqs . they say changing a variable in a statement which refers it twice isn't valid . so
The question of valid or invalid does not figure out here. The fact is that, the ANSI standard says
nothing about such statements, these are called "statements with side-effects".
The outcome is not predictable, as EVERY compiler is free to implement it as it wishes.
Essentially, K&R advises to avoid such statements with side effects. It is _NOT_ a good programming
practice at all.
People administering C language tests should avoid asking such questions, as they make no sense. ;-)
(We have a tendency to make the C test as arcane as possible) ;-)
> anything like
> ++i = i; or
> ++i = i++; or
> printf("%d %d",++i,i++); are not valid & thus may differ from compiler to compiler
^^^^^^^^^
Cheers,
-amar-
--
Amarendra GODBOLE (http://ag.dnsq.org)
Public Key: http://pubkey.dnsq.org
18.97 deg. N / 72.83 deg. E
+0530 GMT