Re: detabbing again
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Wed, 19 Aug 2009 04:03:39 +0100
Frank <merrill@xxxxxxxxxxxxxxxxx> writes:
On Aug 18, 5:21 pm, Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:<snip>
Frank <merr...@xxxxxxxxxxxxxxxxx> writes:
errno = 0;
n = strtol(argv[1], &endp, 10);
// print some values
printf(" argv1 is %ld\n" , n);
printf(" errno is %d\n" , errno);
Calling printf can loose the value of errno. It can be set to non-zero
by printf even if printf succeeds because printf does not document the
use of errno. You have to test immediately, though most systems are
helpful and I don't think anything is going wrong because of this.
Is it better to use fprintf and stderr?
That all have the same property. In general you should test errno
immediately rather than work out what might or might not happen to it.
<snip>
case 2) 0 || 0
If endp == zero then the test condition is true. I think we want to
test argv[1] to see if it is zero and spit this case back to the user
and say "Do you really want to take the tabs out altogether?"
Same here. I have no idea what you are talking about. Why not give
an example call and talk about the effect it has?
I claim that "well-formed" user responses for argv1 are the natural
numbers. If your logic consists or n || m, where n is in the
naturals, then only zero reverses the outcome, given m. I think we
need to split this case off.
What are you talking about? My logic tests *endp (or endp == argv[1])
and errno. What has n got to do with it? What is m?
Of all the naturals, only one is false, namely, zero. I don't think a
control that tests for the truth of argv[1] is going to help this
program decide anything, so I think the point is moot.
I have never suggested testing the truth of argv[1].
I don't mean to be glib here. And I haven't figured out how endp
tells me anything about errors yet, but I'm getting closer. Cheers,
Have you read the specification of strtol? It tells you what happens
to the pointer whose address you pass to strtol (endp in this case).
<snip>
--
Ben.
.
- References:
- detabbing again
- From: Frank
- Re: detabbing again
- From: Ben Bacarisse
- Re: detabbing again
- From: Frank
- Re: detabbing again
- From: Barry Schwarz
- Re: detabbing again
- From: Frank
- Re: detabbing again
- From: Barry Schwarz
- Re: detabbing again
- From: Frank
- Re: detabbing again
- From: Ben Bacarisse
- Re: detabbing again
- From: Frank
- Re: detabbing again
- From: Ben Bacarisse
- Re: detabbing again
- From: Frank
- Re: detabbing again
- From: Ben Bacarisse
- Re: detabbing again
- From: Frank
- detabbing again
- Prev by Date: Re: write error
- Next by Date: Re: detabbing again
- Previous by thread: Re: detabbing again
- Next by thread: Re: detabbing again
- Index(es):
Relevant Pages
|