Is i = i++; bad style?

  • Thread starter lovecreatesbea...
  • Start date
R

Richard Heathfield

Dave Vandervies said:
I would recommend using something fairly short (seven days?) the first
time and doubling it on every offense.

If I ever write my own newsreader (and let's face it, we've all been
tempted to do that), that's roughly how it'll work, although it'll
probably start off at 1 hour rather than 7 days.

Actually, I'm very tempted by Kaz's pennies/dollars analogy, but the
accounting sounds far too much like hard work to be practical.
 
L

lovecreatesbea...

Keith Thompson said:



What did you expect from a troll, Keith? Intelligence and willingness to
learn?

Mr. Thompson own my respect.

and you never.
 
D

Default User

Richard Heathfield wrote:

If I ever write my own newsreader (and let's face it, we've all been
tempted to do that), that's roughly how it'll work, although it'll
probably start off at 1 hour rather than 7 days.

My current one is open source, but written in Delphi. Were it C or C++
I'd be tempted to hack it to add or "improve" features. I'm sure if I'm
glad or not that it would be too much trouble to start.




Brian
 
K

Keith Thompson

Mr. Thompson own my respect.

and you never.

Then you're missing out. Richard Heathfield is a great source of
information here, *if* you're willing to pay attention. He simply had
the good sense to lose patience with you sooner than I did.
 
K

Keith Thompson

John Bode said:
s/wrong/unexpected

Why? Gordon's statement that there are no wrong answers is quite
correct. (If you disagree, please exhibit an answer that would be
wrong.)

On the other hand, there could easily be unexpected answers, such as
causing the Spanish Inquisition to appear.

(My mentioning the Spanish Inquisition will inevitably lead to a chain
of off-topic followups, to the utter bewilderment of anyone not
familiar with Monty Python. Let's just assume we've alread done that
and move on, shall we?)
 
U

user923005

Keith Thompson said:
First off, the exact rule we're talking about (C99 6.5p2) is:
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.
with a footnote:
This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a = i;

Sequence points occur in a number of places: between statements (you
can loosely think of a ';' as marking a sequence point), between the
operands of a ',', '&&', or '||' operator, and in a number of other
places.

<snip>

What is going on here? A real answer? After only 55 or so posts?- Hide quoted text -

- Show quoted text -


There were other answers on the point, but I don't think the O.P. is
really after them anyway.

At any rate, considering this bit from the standard:

"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."

Imagine that you are a compiler writer. The value of the above should
be immediately obvious. Otherwise, you would essentially have to
treat every variable as volatile an almost all optimizations would be
impossible.
 
C

CBFalconer

Default said:
My current one is open source, but written in Delphi. Were it C or
C++ I'd be tempted to hack it to add or "improve" features. I'm
sure if I'm glad or not that it would be too much trouble to start.

Is Xananews the same thing as Xnews, perchance?
 
J

John Bode

Why? Gordon's statement that there are no wrong answers is quite
correct. (If you disagree, please exhibit an answer that would be
wrong.)

I meant that *my* usage of the word "wrong" should be changed to
"unexpected." And I had hoped that the scare quotes around the first
usage of "wrong" would have been a big enough hint.

Oh well. My wife doesn't understand me either much of the time.

[snip]
 
C

CBFalconer

John said:
I meant that *my* usage of the word "wrong" should be changed to
"unexpected." And I had hoped that the scare quotes around the
first usage of "wrong" would have been a big enough hint.

I don't know why it took me so long but this thread is now PLONKed
 
M

Mark McIntyre

No, I sent that post when it is about 3-4 am,

Your english has let you down. "Good night" is only used when
departing / finishing /closing down for the evening. If yuo are
arriving, you say "good evening" or "good morning" depending on
whether its before or after midnight.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
L

lovecreatesbea...

Your english has let you down. "Good night" is only used when
departing / finishing /closing down for the evening. If yuo are
arriving, you say "good evening" or "good morning" depending on
whether its before or after midnight.

Thank you. But we generally consider it very a deep night, it's still
dark and slient :)
 
C

Chris Dollin

user923005 said:
At any rate, considering this bit from the standard:

"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."

Imagine that you are a compiler writer. The value of the above should
be immediately obvious. Otherwise, you would essentially have to
treat every variable as volatile an almost all optimizations would be
impossible.

I think that over-states the case.

[FWIW: I have written pieces of compiler, although not for C, and not
"heavily" optimising.]
 
M

merve

i am new on the c programming ..but must it be in that style??


int main(void)
{
int i;
i = 10;
i++;
printf("%d\n", i);
return 0;
}


is that wrong ?
 
S

santosh

merve wrote:

Please provide context when you're posting to Usenet. Usually this
means that you quote the relevant parts of the article to which you're
replying.
i am new on the c programming ..but must it be in that style??


int main(void)
{
int i;
i = 10;
i++;
printf("%d\n", i);
return 0;
}


is that wrong ?

It's okay except for the fact that you've apparently omitted to
include the stdio.h Standard header. It is needed for printf, among
others. Omitting the necessary headers is likely to invoke undefined
behaviour.
 
U

user923005

I think that over-states the case.

I am not sure that it does. It means that (essentially) there is no
such thing as a sequence point.
[FWIW: I have written pieces of compiler, although not for C, and not
"heavily" optimising.]

Same for me.
 
C

Chris Dollin

user923005 said:
I am not sure that it does. It means that (essentially) there is no
such thing as a sequence point.

I don't think it means /that/; I think -- and I admit it's a while since
I've thought much about it -- what it /really/ affects is storing via
pointers: if a nested `*spoo = x` appears in an expression then any
variable of the right type which might have its address accessible
might be affected. Expressions with no assignments in them are OK.
Expressions which assign only directly are OK if they don't have
any indirect accesses (of the appropriate type).

Of course a function call might hide such an assignment. And the
classic case of indirect addressing is using arrays: what the Bit
Above does it make it a lot safer/easier to optimise array hacking.
I think.

(Array hacking not being a particular domain of interest for me,
which is just as well since I suspect I'm not up to doing it or
compiling it -- better that better people than I handle it. Which
qualifies my "over-states", I think.)
[FWIW: I have written pieces of compiler, although not for C, and not
"heavily" optimising.]

Same for me.

Sibling!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,688
Members
48,796
Latest member
Greg L.

Latest Threads

Top