very much new to c need ur help

O

Old Wolf

You dont seem to get it : I dont care what the RFC says. I do care that
his sigs break some news readers and end up getting requoted. Common
sense over anal retentive I guess.

Common sense says that if news readers can be broken by
some particular message, then it is a bug in the news reader.
Oh, grow up and stop being so prissy. His double sigs break peoples news
readers. End of subject.

So you think that CBFalconer should modify his posting
habits just to work around a bug in your chosen news
reader?

Who had the ego problem, again?
 
R

Richard

Old Wolf said:
Common sense says that if news readers can be broken by
some particular message, then it is a bug in the news reader.

"broken" == not snipping his superfluous signature.
So you think that CBFalconer should modify his posting
habits just to work around a bug in your chosen news
reader?

And thousands of others. And nice snipping. slrn/gnus are not "my" news
readers. One of them happens to be one I use.
Who had the ego problem, again?

Sorry?

It's not me sticking to some ridiculous double sig despite being asked
nicely to fix it or move to an alternative news service.

An analogy to this would be some bastard of a neighbour who turns his
stereo up every day during the daylight hours because he deems it legal.
This despite the fact that it is incredibly annoying and he has been asked
to turn it down. I must admit I have allowed "Chuck" to get under my
skin on this one primarily because of his constant net nannying of
others and his incredibly arrogant put downs of nOObs and beginners
whenever he can. Yet he does not practice what he preaches.

Still, he is in the killfile now and good riddance IMO.
 
C

CBFalconer

Charlie said:
.... snip ...

Showing off code where getc(fp) gets stored into an unsigned
variable and then compared to EOF does not constitute good advice.
It may qualify as a quiz or a puzzle (how can you make this code
break on a DS9K).

Don't be silly. I responded to that, and the code is accurate and
portable. The only possible hitch is when sizeof int == 1.
 
C

Charlie Gordon

CBFalconer said:
Don't be silly. I responded to that, and the code is accurate and
portable. The only possible hitch is when sizeof int == 1.

I did not say it was inaccurate, I said it is not advisable to do what you
did there because it is too subtle.
Using the wrong type because it saves half a line somewhere later in your
function is silly.
The time spent verifying the expression correctness by several of the most
savvy regulars on this group shows how pervert it is to advise newbies to do
it. We might as well call it obfuscation.
 
S

santosh

Charlie Gordon said:
I did not say it was inaccurate, I said it is not advisable to do what
you did there because it is too subtle.
Using the wrong type because it saves half a line somewhere later in
your function is silly.
The time spent verifying the expression correctness by several of the
most savvy regulars on this group shows how pervert it is to advise
newbies to do it. We might as well call it obfuscation.

s/pervert/perverse

Incidentally we had a long running flame war the last time that the
word "perverse" was employed by one of this group's regular.
 
P

pete

CBFalconer said:
Don't be silly. I responded to that, and the code is accurate and
portable. The only possible hitch is when sizeof int == 1.

There's also a problem when INT_MAX equals UINT_MAX.
In that case, each negative int value,
when converted to type unsigned,
becomes a non negative value within the range of type int.
 
C

Chris Hills

thank you for correcting me where i was wrong . actually i was not
aware of this . i came to know about Google newsgroups from my book as
newsgroups is one of the topic which is taught to us in our college.

You are not on Google Newsgroups.

You are on Usenet. Google just does a strange web front end for googol
users. Most of the world does not use google for news.
 
C

CBFalconer

Charlie said:
I did not say it was inaccurate, I said it is not advisable to do
what you did there because it is too subtle. Using the wrong type
because it saves half a line somewhere later in your function is
silly. The time spent verifying the expression correctness by
several of the most savvy regulars on this group shows how pervert
it is to advise newbies to do it. We might as well call it
obfuscation.

Bien. This I can discuss. The point in that code is to process
the char. sequence incoming. In the process it is necessary (once)
to detect error/eof by picking out the special EOF character.
Absent that, it is necessary to have unsigned char values to
satisfy the requirements of such routines as isdigit(), etc. It
also avoids the evils of mixing unsigned and signed values in
comparisons, for the range check.

Thus I maintain the single use in the EOF check is optimum in
clarity. Note that it totally avoids casts.
 
C

CBFalconer

pete said:
There's also a problem when INT_MAX equals UINT_MAX. In that case,
each negative int value, when converted to type unsigned, becomes
a non negative value within the range of type int.

No there isn't. The only values (outside EOF) stored are those of
input chars. As long as sizeof int > 1 there can be no confusion.
 
P

pete

CBFalconer said:
No there isn't. The only values (outside EOF)

EOF is the whole problem.
stored are those of
input chars. As long as sizeof int > 1 there can be no confusion.

It has nothing to do sizeof(int),
and everything to do with when INT_MAX equals UINT_MAX.

If you have
unsigned ch = getc(fp);
and ch is equal to '\0',
then you have no idea whether or not ch is also equal to EOF.

If you have
unsigned ch = getc(fp);
and ch is equal to '\n',
then you have no idea whether or not ch is also equal to EOF.

You have no idea whether or not getc(fp)
returning an ordinary character,
is also equal to ((unsigned) EOF), and the problem is
that you use that equality as a loop control expression.



It's almost as though you can't read.
 
M

Mark McIntyre

Richard said:
The sig is measured from the bottom of the page. Everyone knows that.

Everyone in your fantasy land.

Heck, I hate training new newsreaders. Anyone know how to import
killfiles from Agent to Thunderbird?
 
K

Keith Thompson

CBFalconer said:
Bien. This I can discuss. The point in that code is to process
the char. sequence incoming. In the process it is necessary (once)
to detect error/eof by picking out the special EOF character.
Absent that, it is necessary to have unsigned char values to
satisfy the requirements of such routines as isdigit(), etc. It
also avoids the evils of mixing unsigned and signed values in
comparisons, for the range check.

getc() returns a result of type int, containing either the character
that was read (as an unsigned char converted to int) or the value EOF.

The is*() functions take an argument of type int, containing either the
character to be tested (as an unsigned char converted to int) or the
value EOF.

See the similarity? Perhaps storing the result in an unsigned object
doesn't mess things up, but it takes far too much effort to prove it.

[...]
 
C

Charlie Gordon

CBFalconer said:
Bien. This I can discuss. The point in that code is to process
the char. sequence incoming. In the process it is necessary (once)
to detect error/eof by picking out the special EOF character.
Absent that, it is necessary to have unsigned char values to
satisfy the requirements of such routines as isdigit(), etc. It
also avoids the evils of mixing unsigned and signed values in
comparisons, for the range check.

Let's discuss it then.
I'll quote your proposed code again, to document this debate:
The cleanest way is to input chars until you have something that
will not fit. For example:

unsigned int rdvalue(FILE *f) {
unsigned int ch, value, err;

value = err = 0;
while (EOF != (ch = getc(f))) {

You are indeed mixing signed and unsigned int in this comparison, something
you qualify as evil, which is also my opinion.
/* ch contains an int, which is the value of the char */
if (!isdigit(ch)) break; /* Only interested in digits */

You are passing an unsigned int to isdigit. isdigit is supposed to receive
an int, with specific constraints on its value. I'm not sure if the
language of 7.4p1 is enough to make isdigit invoke undefined behaviour when
passed an unsigned int, but consider that converting -1U to an int may cause
problems and does not necessarily produce the value -1. It is not an actual
problem with your code, but a well hidden bear trap for the next reader, who
might consider simplifying said code by combining the test for EOF and that
for isdigit. With ch defined as unsigned int, ``while ((isdigit(ch =
getc(f)))'' is not well defined.

Consider for example the following classic implementation of isdigit:

#define EOF (-1)
extern unsigned char __ctype_flags[UCHAR_MAX + 2];
#define __C_DIGIT 1
#define isdigit(c) (__ctype_flags[(c) + 1] & __C_DIGIT)

On platforms where size_t is larger than unsigned int (both windows and
linux 64 bit), invoking isdigit with (unsigned)EOF will invoke undefined
behaviour.

It is therefore not advisable to store fgetc(fp) in an unsigned int before
testing for EOF.
ch = ch - '0'; /* form digit value */
if (((UINT_MAX - ch) / 10) > value) {

This test is incorrect, as was explained in another thread.
/* overflow detected, decide what to do */
ch = ch + '0'; /* restore char value */
break;
}
value = 10 * value + ch;
}
ungetc(ch, f); /* keep exit char for the user */

Same problem as above with the value EOF: converting it back to int as
expected by ungetc() may cause overflow. It would be better to not call
ungetc with the value EOF at all, for example invoking it in the loop,
before the break statements.
return err;
} /* untested - you check it out */

untested indeed.
Thus I maintain the single use in the EOF check is optimum in
clarity. Note that it totally avoids casts.

I obviously disagree: the code is not optimum in clarity, it is not
conforming, you avoid casts, but rely on implicit conversions with potential
overflows...
 
P

pete

pete said:
EOF is the whole problem.


It has nothing to do sizeof(int),

Which is not to say that there isn't a problem
with your function when sizeof(int) equals one,
but it's an other different problem.
 
J

Joe Wright

pete said:
Which is not to say that there isn't a problem
with your function when sizeof(int) equals one,
but it's an other different problem.
pete, Please expand on the case for INT_MAX == UINT_MAX. I think that
int and unsigned int are the same width (in bits). The int must have a
single sign bit, not a value bit. Given a 32-bit int, int has 31 value
bits and unsigned int has 32. UINT_MAX == (unsigned)INT_MAX*2+1 it would
seem.
 
C

CBFalconer

Keith said:
CBFalconer wrote:
.... snip ...
^^^^^^^^^^^

getc() returns a result of type int, containing either the character
that was read (as an unsigned char converted to int) or the value EOF.

The is*() functions take an argument of type int, containing either the
character to be tested (as an unsigned char converted to int) or the
value EOF.

See the similarity? Perhaps storing the result in an unsigned object
doesn't mess things up, but it takes far too much effort to prove it.

See the underlined portion above?
 
C

CBFalconer

Charlie said:
"CBFalconer" <[email protected]> a écrit:
.... snip ...

Let's discuss it then.
I'll quote your proposed code again, to document this debate:


You are indeed mixing signed and unsigned int in this comparison,
something you qualify as evil, which is also my opinion.

No, this is an equality check, not a comparison. The evils never
arise.
You are passing an unsigned int to isdigit. isdigit is supposed to receive
an int, with specific constraints on its value. I'm not sure if the

You just may have a point here. My argument is that the value is
known to be positive, and by definition the unsigned and int
representations of positive int values are identical. EOF is never
passed.

.... snip ...
Consider for example the following classic implementation of isdigit:

#define EOF (-1)
extern unsigned char __ctype_flags[UCHAR_MAX + 2];
#define __C_DIGIT 1
#define isdigit(c) (__ctype_flags[(c) + 1] & __C_DIGIT)

On platforms where size_t is larger than unsigned int (both windows
and linux 64 bit), invoking isdigit with (unsigned)EOF will invoke
undefined behaviour.

But you forget that isdigit expects to receive an int, that EOF has
been removed, and that unsigned ints have the identical
representation as positive ints.
It is therefore not advisable to store fgetc(fp) in an unsigned int before
testing for EOF.

NIT - I specifically use getc, so that it can be a macro invocation
and thus can be much quicker than a system function call.
This test is incorrect, as was explained in another thread.

I'm not bothering to check it out now, but unsigned int is needed
for proper range checking. I think the only fault is the
replacement of > with <.
Same problem as above with the value EOF: converting it back to
int as expected by ungetc() may cause overflow. It would be
better to not call ungetc with the value EOF at all, for example
invoking it in the loop, before the break statements.

No problem with EOF, because if getc returned EOF the subtraction
(and addition) of '0' does not occur.
untested indeed.

Which is why I added the comment :)
I obviously disagree: the code is not optimum in clarity, it is
not conforming, you avoid casts, but rely on implicit conversions
with potential overflows...

I trust I have answered your objections. I think everything is
covered.
 
C

CBFalconer

pete said:
CBFalconer wrote:
.... snip ...

EOF is the whole problem.


It has nothing to do sizeof(int),
and everything to do with when INT_MAX equals UINT_MAX.

If you have
unsigned ch = getc(fp);
and ch is equal to '\0',
then you have no idea whether or not ch is also equal to EOF.

If you look back at the original code the controlling expression is
approximately:

while (EOF != (ch = getc(f))) {
....
}

and everything you are talking about is within the .... where the
value of EOF can never arise.
 
W

Walter Roberson

Richard said:
You dont seem to get it : I dont care what the RFC says. I do care that
his sigs break some news readers and end up getting requoted.

I see. You are valuing convenience over correctness. That's an
unusual attitude to take in comp.lang.c, which relies heavily upon
what is correct according to the standards -- unusual unless, that is, you
advocate that the next generation of the standards should be oriented
towards mandating the current "majority rules" behaviour, at the
expense of flexibility. Should we be dropping signed-magnitude
and 1s complement and fixing the order of parameter evaluation
in a function call? Those would make C more convenient for most people,
and who cares about the rest, eh?
 
S

santosh

Walter Roberson said:
I see. You are valuing convenience over correctness.

Also the word "some" is indeed important. I can say that the double sig
is snipped out in it's entirety by KNode, Pan, SeaMonkey and
Thunderbird.

So it's probably not true that CBFalconer's sig is breaking the majority
of newsreaders. It might be that only a few of them (among them slrn
and Gnus), are choking on this.

<snip>
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top