Can mystr[i]=mystr[ii] be a problem when i==ii

J

Joe

I have a string parsing function which uses above code. i and ii are same at
first but as my loop goes on ii is incremented more. I could do
if (ii!=i)
mystr=mystr[ii];

but I want to limit unnecessary code.
 
R

Richard Heathfield

Joe said:
I have a string parsing function which uses above code. i and ii are
same at first but as my loop goes on ii is incremented more. I could
do if (ii!=i)
mystr=mystr[ii];

but I want to limit unnecessary code.


No, you don't need the test. Well done for asking, though, because it's
not as obvious as it sounds. The relevant rule 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 accessed only to
determine the value to be stored."

Your code (as written above) obeys this rule, and there is no problem.

It is not difficult to imagine similar code which could fail, however.
For example:

mystr = mystr[i++]; /* BAD! */

would violate the requirement quoted above.
 
C

CBFalconer

Joe said:
With "above code" I mean:
mystr=mystr[ii];


You haven't gotten the point. News articles may or may not be
received anywhere. Thus each article should stand entirely by
itself. That means, among other things, proper quoting. The
following sig. may make things clearer.

--
If you want to post a followup via groups.google.com, ensure
you quote enough for the article to make sense. Google is only
an interface to Usenet; it's not Usenet itself. Don't assume
your readers can, or ever will, see any previous articles.
More details at: <http://cfaj.freeshell.org/google/>
 
U

Urs Beeli

["Followup-To:" header set to comp.lang.c.]
Joe said:
I have a string parsing function which uses above code. i and ii
are same at first but as my loop goes on ii is incremented more.
I could do
if (ii!=i)
mystr=mystr[ii];

but I want to limit unnecessary code.


I see no 'above code'.


I believe he was referring to the code in the subject line :)

Cheers
/urs
 
R

Richard Heathfield

Urs Beeli said:
["Followup-To:" header set to comp.lang.c.]
Joe said:
I have a string parsing function which uses above code. i and ii
are same at first but as my loop goes on ii is incremented more.
I could do
if (ii!=i)
mystr=mystr[ii];

but I want to limit unnecessary code.


I see no 'above code'.


I believe he was referring to the code in the subject line :)


Then he would do well to learn that not everybody uses a newsreader that
displays the subject line conveniently whilst the body of an article is
being displayed.
 
P

Paul S. Person

Joe said:
With "above code" I mean:
mystr=mystr[ii];


You haven't gotten the point. News articles may or may not be
received anywhere. Thus each article should stand entirely by
itself. That means, among other things, proper quoting. The
following sig. may make things clearer.


<snip>

But will they be received without the Subject line? That it where the
code in question is hiding -- and that makes it a part of every single
post in the thread.

Or does your newsreader display the Subject /below/ the text?
 
R

Richard Tobin

I believe he was referring to the code in the subject line :)
[/QUOTE]
Then he would do well to learn that not everybody uses a newsreader that
displays the subject line conveniently whilst the body of an article is
being displayed.

And those people would do well to complain to their newsreader
suppliers. How can they be so foolish as to not display the subject
readably above the message?

-- Richard
 
M

Mark McIntyre

Or does your newsreader display the Subject /below/ the text?

Mine displays it in the titlebar of the window, which is not even
remotely close to the text I'm reading.

But thats hardly the point. Do you write your letter on the outside of
the envelope, and just say "see outside" on the actual paper inside?
--
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
 
M

Mark McIntyre

Then he would do well to learn that not everybody uses a newsreader that
displays the subject line conveniently whilst the body of an article is
being displayed.

And those people would do well to complain to their newsreader
suppliers. [/QUOTE]

Why? Its a defect in the poster, not the reader. Do you expect every
page of a book to have the chapter heading readably above the text?
Sure some do, but many don't. Its not regarded as mandatory.
How can they be so foolish as to not display the subject
readably above the message?

Perhaps because they assumed that the subject would be a brief summary
of the message useful for reading as part of a list of other messages,
and the main text would be in the body, useful for reading as a
message by itself.
--
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
 
R

Richard Tobin

And those people would do well to complain to their newsreader
suppliers.
[/QUOTE]
Why? Its a defect in the poster, not the reader. Do you expect every
page of a book to have the chapter heading readably above the text?

Your analogy is irrelevant. I wasn't suggesting it should show it
above every page of the message. Obviously it would be absurd to have
a message so long that it went over multiple pages and yet required
you to constantly refer to the title.
Perhaps because they assumed that the subject would be a brief summary
of the message useful for reading as part of a list of other messages,
and the main text would be in the body, useful for reading as a
message by itself.

But they were wrong, weren't they.

-- Richard
 
M

Mark McIntyre

But they were wrong, weren't they.

Your argument is "idiots might use our software, so lets cater for
them in our interface".

Microsoft Bob anyone?
--
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
 
R

Richard Tobin

Your argument is "idiots might use our software, so lets cater for
them in our interface".

Why is it idiotic to assume that the title will be visible when
reading the start of the article? It's perfectly natural user
interface design. It seems to me that you *want* life to be difficult
for people who happen not to look at things your way.

-- Richard
 
R

Richard Heathfield

Richard Tobin said:
Why is it idiotic to assume that the title will be visible when
reading the start of the article?

FWIW, I don't think it's *idiotic* to assume that. But nevertheless I am
given to understand that it is a false assumption, since (apparently)
there *really are* newsreaders that don't work that way.
It's perfectly natural user
interface design. It seems to me that you *want* life to be difficult
for people who happen not to look at things your way.

For my part, I want life to be *easy* for people who happen not to look
at things my way. My own newsreader does display the subject line in a
convenient way, but I don't insist that everyone uses a newsreader like
mine. Therefore, on the (fairly rare) occasions that I start a new
thread, I don't rely on the subject line being visible to readers of my
article. That is one way in which I try to make life easier for other
people, regardless of their newsreader choice.
 
D

Default User

Richard said:
Richard Tobin said:

FWIW, I don't think it's idiotic to assume that. But nevertheless I
am given to understand that it is a false assumption, since
(apparently) there *really are* newsreaders that don't work that way.


For my part, I want life to be easy for people who happen not to look
at things my way. My own newsreader does display the subject line in
a convenient way, but I don't insist that everyone uses a newsreader
like mine.

In mine, it's sort of semi-convenient. It's displayed at the top of the
message, but in a block with other stuff:

From: Richard Heathfield <[email protected]>
Subject: Re: Can mystr=mystr[ii] be a problem when i==ii
Date: Wed, 13 Jun 2007 23:05:30 +0000
Newsgroups: comp.lang.c
User-Agent: KNode/0.7.1


So, yeah, it's there, but I have to go hunt a bit to find it. It's also
less convenient for replies, as I'd then have to go and make special
arrangements to include that in the reply.

The bottom line is, it's usenet standard practice to fully describe
your question or comment in the body of the message. The subject should
be similar to the headline for a newspaper, a short catchy lead-in to
the main fun.



Brian
 
K

Keith Thompson

Why is it idiotic to assume that the title will be visible when
reading the start of the article? It's perfectly natural user
interface design. It seems to me that you *want* life to be difficult
for people who happen not to look at things your way.

Let me summarize.

Usenet client programs *should* conveniently display the subject of a
message when displaying the body of the message, at least when
displaying the first page of the body of the message.

It's not clear that all client programs do this; I don't think I've
ever seen one that doesn't, but there are plenty of client programs
I've never seen.

People posting questions *should* put the question in the body of the
article, and not assume that it's going to be noticed by everyone who
reads the message. This doesn't necessarily mean repeating the
subject verbatim in the body. Most posters here get this right, so
there's no shortage of good examples.
 
O

Old Wolf

Your argument is "idiots might use our software, so lets cater for
them in our interface".

That's regarded as a core principle in user
interface design, these days.
Microsoft Bob anyone?

Poor example. Bob was a new user-interaction paradigm
(which turned out to be more difficult to use than
the designers expected), not a catering for idiots.
 
C

Chris Dollin

Richard said:
Why is it idiotic to assume that the title will be visible when
reading the start of the article? It's perfectly natural user
interface design.

Indeed, this 'ere newsreader shows the title above the article
(and the headers). But /that's not where I'm looking/. I'm
looking at the article. It's a flow-killer to go and eyegrope
for the subject (yes, it's highlighted -- the interface is
doing it's best) and it /shouldn't be necessary/.

When the code in the subject line is called "the above code",
that doesn't help.
 
R

Richard Bos

Old Wolf said:
That's regarded as a core principle in user interface design, these days.

And it's wrong, because it leads to _everybody_ being treated as idiots.

"My First^w Computer"

Richard
 
R

Richard Tobin

And those people would do well to complain to their newsreader
suppliers. How can they be so foolish as to not display the
subject readably above the message?
[/QUOTE]
One example is a device with one line text displays.

This would equally be a problem for an article that described the
problem on the first line.
Another may simply scroll the headers out of the way.

It's only relevant for short articles. For longer articles, the start
of the article is going to be just as scrolled-away as the title is.

-- Richard
 

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

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top