Segfault City

M

Malcolm

pete said:
Abnormal program termination,
as a means of handling invalid argument values,
isn't intelligence, it's just lack of imagination.
In Java you would throw an invalid argument exception.
Theoretically the Java method is better, because it means that control is
passed to higher level functions which can take remedial action. In practise
I haven't found it to be all that helpful, since all you can really do on
encountering an internal error is terminate anyway. If you know where the
errors are, you fix them rather than try to catch them and recover.

PI * 2 = assertion failure line 303

is a lot better than

PI * 2 = -22

which is what you are likely to get if you quietly return an unsupported
character as -1.
 
P

pete

Herbert said:
int ctoi(int c)


a bit shorter

inline int ctoi(int c) {
return isdigit(c) ? c - '0' : -1;
}

Or if I have to be sure that it will compile on pre ANSI compilers I
would just
#define CTOI(c) isdigit(c) ? (c) - '0' : -1

Now that it has an int type parameter,
how should it deal with a negative int value
like ('5' - 1 - (unsigned char)-1)?

/* BEGIN new.c */

#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#define NEG_5 ('5' - 1 - (unsigned char)-1)

int main(void)
{
int five;

assert(INT_MAX > UCHAR_MAX);
five = NEG_5;
if (0 > five && isdigit((unsigned char) five)) {
putchar(five);
}
putchar('\n');
return 0;
}

/* END new.c */
 
K

Keith Thompson

Malcolm said:
Should, yes, but that's the incompetent colleague who called your function
with a non-digit at fault. The question is, once the disaster has happened,
what is the least damaging thing to do. Shut down the game, or display the
wrong score?
There isn't necessarily an easy answer to that one, but normally it is
better to keep things moving.
[...]

I think there are three very different possible function
specifications being discussed here, and it's important to distinguish
among them.

/* 1 */
int char_to_digit(int c);
/*
* For an argument in the range '0' to '9', returns its numeric
* value in the range 0 to 9.
* For an argument outside that range, returns -1.
*/

/* 2 */
int char_to_digit(int c);
/*
* For an argument in the range '0' to '9', returns its numeric
* value in the range 0 to 9.
* For an argument outside that range, the behavior is not defined
* (or aborts the program or whatever).
*/

/* 3 */
int char_to_digit(int c);
/*
* Returns the numeric value of the character arguments, interpreted
* as a decimal digit.
*/

For the first version, the caller is free to pass any value it likes,
and can depend on getting consistent results. There is nothing
incompetent about calling it with a non-digit, any more than there's
anything wrong with calling free with a null pointer.

For the second version, calling the function with a non-digit is a
logical error. Since this fact is well documented, the error is
entirely the caller's fault. (You might complain that you'd have
preferred version 1, but that's just too bad.)

Unfortunately, the third version is all too common. It's apparent
that the author didn't bother to think about non-digit arguments.
This must be treated as equivalent to the second version.
 
B

Bill Pursell

Malcolm said:
In Java you would throw an invalid argument exception.
Theoretically the Java method is better, because it means that control is
passed to higher level functions which can take remedial action. In practise
I haven't found it to be all that helpful, since all you can really do on
encountering an internal error is terminate anyway. If you know where the
errors are, you fix them rather than try to catch them and recover.

I disagree that the Java method is better. The two are
not comparable. The C method is to do the checks
only while you're debugging, and to avoid them at
run-time in production for the sake of efficiency. ie,
the C method assumes that the designer knows
what she's doing and that the program is correct.
The Java method assumes the designer doesn't
understand diddly and holds her hand forever.
 
H

Herbert Rosenau

Richard's strategy is to post a lie that then spreads confusion, and
causes his butt buddies, and people frightened of him, to repeat
character assassinations. It is Swift Boating.

YOU are the only liar here around.
Here is Richard's lie:


</heathfield>

As you can see, it's not a straightforward test for numerics. It uses a
system library function that may or may not be available depending on
the C environment dishonestly and converts to numerics.

You are a iar as proven by you own words above. There is no system
libaray or a function out of one. There is only a function of the
standard C library that is guaranteed by the standard since the very
first one occured - and even documented in K&R years before ANSI C89
was created.
I call this Swift Boating because it appears that Richard deliberately
lied, as did the President about Kerry's war record, in order to leave
others with an impression that since he's the Expert (as the President
is the "President") he would be honest, therefore any objection is
whining.

It doen't matter what you call this. Anybody who had ever readed the C
bible more than 20 years ago would know of that function. You've
proven already as self fucking liar with absolutely no knowledge of C.
He then proceeded to massively confuse this issue by actually talking
about EBCDIC when perhaps less than 1% of C programs use IBM
mainframes.

Another lie from you. You has proven yourself again as some twit who
knows nothing about he quacks.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

(Actually, using my normal gcc switches, it doesn't even get past TP3, but
it will at least compile if you just use gcc -o foo foo.c, after hacking it
around a bit to do things like mending the line-spanning single-line
comments and string literals, which - in fairness to the author - are
probably an artifact of the Webification of the code.)

I wonder how long I'll take to stop laughing.

I can understand you responding, Rirchard, since the web page contains a
comment about you, but I think it would have been more helpful to Edward
Nilges if you'd just sent him a private e-mail pointing out some of the
errors, such as the use of strcat in

printf( strcat(strcat("The %s program calculates primes ",
"in a user-specifiable range. "),
"Use the following syntax: %s"),
strArgValues[0],
SYNTAX_REMINDER );

None of the bloody beginner who had understund 1% of C and what K&R
says about would ever write such bullshit as you. So you've proven
yourself as having not even an idea what C is, to dumb to understund
it and lying around.
Actually, I started in machine language. And as it happened I had to
refigure the syntax since I had (briefly) started re-using C.

You have never written a single procedure in C free of errors. You've
not even an idea what C is and would never learn it as you've proven
already.

Look what (e-mail address removed) says about himself:
You are clearly a loser. You don't even know that a professional would
not feel right about using a management puff phrase like "quality
assurance" (which usually and in practice means the eradication of
anything like quality) but would instead post reasons why he felt the
code to be incorrect. It may be (code is like that) but after several
months' hiatus I see nothing wrong.

So long you says that about yoursef you are 100% correct. If you means
somebody else who has at lest 20 hours experience in C you are a self
fucking liar.

The code ran on the Navia compiler. Do illumine us.

It does NOT run under any real OS.
Not from people whose main interest is establishing their shaky
self-confidence exclusively on sand (silicon) by tearing down others.

We've learned already that you are only a twit who is absolutely
learresistent.
Who are afraid to make CONSTRUCTIVE suggestions for modification, since
they might recursively be flamed because when you make a CONSTRUCTIVE
suggestion it contains other than negative assertions, and each one is
recursively subject to lampoon by people as "wrong" who cannot even say
why in clear English, but must instead refer to the idiosyncrasies of
their favorite compiler.

The description of yourself is good. But confuse that not with any
other peoples around the world. You are the only troll.
This discussion is useless. I have written enough code to be far more
interested in my competence in more important areas of life (such as
common decency) than "competing" with thugs...who were not invited to
post at a moderated site, and will be excluded should they choose to do
so in this matter by the moderator.

What code? Surely, not a single line of code in C that is in some
productive program. You've proven yourself really as true washout.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

Richard Heathfield wrote:
The developer dot star post was not any attempt to "teach" C. You've
concealed the fact that in the post there is full disclosure that I was
temporarily returning to C to do "global" computing, might make errors,
had made errors, and trusted a collegial site to make any corrections
needed in the spirit of open source.

Lie no. one. The page claims you are a teacher - what itself is a lie
as the page proves in the source at its end.
Whereas you've set yourself up as a *guru* and yet you have lied,
saying that a "straightforward test for numeric digits" is one when it
used isdigit to make the test!

The next lie. The onoly who claims to be a guru is
(e-mail address removed), even as (e-mail address removed) proves himself
constantly that he knows nothing about C.
My code may have been "obscure" if you so misunderstood the problem but
you're hopeless if you can present a USE of a system function as the
solution. You're a thief of intellectual property and a liar.

The next lie. Your code IS obscure, not errorfree and shows clearly
that you knows nothing about C.
Who? Amateur programmers, retirees with anger management problems, and
script kiddies? I am soooo scared.

When you writes this about yourself, then, but only then you are
right.
...and completely misleading, Monkey Boy, which was your intent: to
confuse in a deliberate campaign of Swift Boating as you did with
Schildt.

When you writes that about yourself, then, but only then you are
right.
I taught SAS C in 1989 when I was a daily user of C (today, I have, it
seems, forgotten more *real* C than you will ever know). EBCDIC C
programming is a rarity and in ASCII the programmer has to worry about
letters, which have what you call "code points" higher than '9'.

The ONLY sensible way to code the test remains

if (intCharValue >= [int]'0' && intCharValue <= [int]'9')

Another sample that shows perfectly that you does not know what C is.
Anybody else with not more than 20 hours practise in programming C
will know what you lack of knowledge is on that line.
NOT in the sense that this won't "break" someone's C environment but in
the sense that the final C code in a particular C environment has to be
an && condition which shows the minimal assumption, that digits are
adjacent.

Another lie from you. You does not even know what C is as proven
above.
Your big lie is that there is one C when in fact nearly all C
programmers have to use a dictated and not fully standard compiler.
Your code tells them to use a library function, isdigit(), which I
suppose is part of your Standard but may not be available elsewhere.

Acusing one in havinbg no knowledge by proving youself again that the
only who has any possible lack of knowledge is yourself is making
yourself a fool.
I may have missed it. Perhaps it's a fundamental part of the toolkit of
every C programmer, and I am too dumb to see it. But here, your lie
remains, because you call a use of the function "a straightforward test
for numerics" when it isn't.

You proves yourself again that you are nothing else than a fool. Name
one, only one programmer on the world who will use printf but will be
unable to use isdigit. You proves yourself again as fool.

Has you ever readed the standard from 1989? No, surely not.
Has you ever tried to find and read the standard from 1999?

No, surely not, the fool (e-mail address removed) is unable for that.
Furthermore it is my understanding that most C library functions can be
coded in C. A conforming definition would use your Standard's guarantee
that the numeric value of digits are adjacent, and would be in fact my
&& test of being in the interval.

(e-mail address removed) proves himself again as too dumb to learn a bit
about C.
Your code doesn't "break" because it uses a magic function which isn't
available to all C programmers. It doesn't do the job it says it will
do. Furthermore, it makes the legacy assumption that all characters are
bytes.

Another lie of the fool who named himself as (e-mail address removed)
OK, I don't understand the Standard's guarantees. But you don't know
how to code clearly (and people who think your code is clear are
deceiving themselves), and you implemented a solution that doesn't do
the job you says it does.

The fool (e-mail address removed) lies again.
As was the case in 2002, you've spread confusion again because your
purpose here is to character assassinate and trash, as in your campaign
against Schildt. You now admit that my code doesn't "fall foul".

Another lie of the fool (e-mail address removed)
Your claim was so outre that earlier this evening I understood you to
be claiming that you merely needed to test for greater than or equal to
zero to check for a number. I now realize that your praxis was even
worse.

More lies from the fool (e-mail address removed)
As was the case in 2002, you've made deliberate misstatements in order
to Swift Boat and spread confusion.

Another lie from the fool (e-mail address removed). He has nothing
learned since then.
**** the standard, and **** you. You have lied consistently, about
Schildt, in 2002, and here:

No the fools blames himself again that he does not know what C is.

Look what the fool (e-mail address removed) says to himself:
And you are lying.

And here is how (e-mail address removed) defines himself:
Like most Swift Boaters and most liars in business, you are fearful of
and resentful of authority and in search therefore of easy "marks" to
bully with your lies. C cannot be "standardized" because it is an
assembly language, and **** ISO if it makes this claim.

(e-mail address removed) continueing speaking about himself:
I am in NO mood to read your code. You are a cheap liar, a code monkey,
and a thug.


--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

On Sat, 24 Jun 2006 18:02:58 UTC, (e-mail address removed) wrote:

Look what the fool says about his sieve function he published on his
WEB page:
I'm not a C "expert" by your lights, but I am an expert programmer, and
the above is one of the silliest things I've ever seen posted on the
net. You may be a "recognized C expert", but you can't program and
should not be permitted to write software or write about software. Here
is why:

(1) You call the code a "straightforward test for numerics" but it
isn't any such thing. It assumes that the library contains an
printf()

function and doesn't "test" at all. Instead, using

printf()

(which makes your statement wrong and a lie because isdigit
does the work you claim "your" code does) and then converts the digit
to a number.

by ignoring that the method he is using strcat() is proven as any
source for undefined behavior he claims were ok.

No body has an idea what he means with the difference between ASCII
and EBCDIC as each conforming compiler will hide the differences
perfectly.
This would be a good thing. The problem is that actual working C
programmers can't be sure of having a fully conforming implementation
for legacy code, and don't waste time if they're smart making legacy
programs conform to your favorite standard. And, you intentionally
mislead them, as a self-appointed C expert, by saying that your code is
a "straighforward test for numerics" when it is not.

In your code, assuming that the C environment the programmer is using
(which doesn't have to be standard) has an isdigit, you don't break if
the digit value is greater than the value of 9. However, your code,
starting with your claim, is a lie, and you are posting (perhaps as a
paid agent) disinformation in a campaign of character assassination
similar to that you conducted against Herb Schildt. **** you.

Why does the fool then use printf(), and even strcat() in his
incompatible crap? He thinks as it seems only the function he knows of
are in each standard library and anything else does not exist.

Only a fool like (e-mail address removed) can think so.

Look what the fool (e-mail address removed) says about himself:
You're a code monkey and on the job, if this is your style, your
interest is solely in spreading confusion, and, probably, office
politics and character assassination.


Obscure? Difficult to read? Give me a break.

Obscure, faulty, errornous, blaming (e-mail address removed) as fool.

There will be no beginner in C with more than 40 hours practise in
writing C who will not able to write a better, more readable, quicker
and standard conforming sieve than (e-mail address removed) will ever
been able to even if he tries that for the next 100 years dayly 16
hours long.



--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

Again, the Standard is not implemented by many C environments and
people come here for guidance on C praxis...not the Standard.

Come on fool, name one C implementation wiritten after 1. 1. 1992 that
is not of the C standard released at 1989.

Hey and even The very first C compiler written by K&R is coming with a
standard library holding isdigit() beside the other functions you
claims not any C compiler were aware of, like printf, strcat and so
on. But why does you use printf, strcat and others - even as you are
unable to use them right as your own source proves.
I make money, so I'm ok

Thiefes maks money, so they are ok?
I works all night and I sleeps all day

So you're a devil?
I puts on women's clothing

We know already that you're a fool, nothing new.
And I hangs around in bars

as most fools, right.




--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

To me, the presence of "assert" in code
indicates that the code is still a work in progress.
Why? There is no need to edit a well tested module only to remove
assert(). If you had a use for it, simply let it alone. The productive
compile will remove it alone.

True, I had never had a need to use assert myself, but I tolerate it
when I see it, when its call is justified by the job it does.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

I believe the following function to be high-quality, and that it should
be unchanged when brought into the Release version:

unsigned CharDigitToInt( int const c )
{
assert( c >= '0' && c <= '9' );

return c - '0';
}

No, because that does NOT catch an error a programmer may have done.
But it will crash the program by an mistake the user will correct
shorthand instead to replace the whole database table the program has
currently in an unstable state because it is in middle of work on.

Will you crash your progam too when a user mistypes his password? Will
you crash your program only because the user has typed 2=0067!"/"!
instead of 2006/12/21? That is what your assert() above will do.

assert() is good to catch programmers faults but not to catch
something else.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
H

Herbert Rosenau

Herbert Rosenau said:
int ctoi(int c)


a bit shorter

inline int ctoi(int c) {
return isdigit(c) ? c - '0' : -1;
}

Or if I have to be sure that it will compile on pre ANSI compilers I
would just
#define CTOI(c) isdigit(c) ? (c) - '0' : -1
[...]

I *hope* you meant

Yes.
#define CTOI(c) (isdigit(c) ? (c) - '0' : -1)

And of course this evaluates its argument twice, so the caller has to
be careful about that.

I'd probably just drop the "inline" (and add "static" if it's only
used in one file) and count on the compiler to inline it for me if it
chooses. If it turned out to be a performance bottleneck, *then* I
might think about making it a macro.
I prefere C98 since I own a C98 compiler for my environment. Befor
that my C89 compiler (the one the developer of the OS had delivered in
1997 was already aware of inline as an well documented extension.

For developement tools: I don't trust the newest and hottest version
by experience. But since 3 years I know of 2 different compilers
mostenly C98 compilant. There are a small rest of functionality
already not existent - but I have never seen a need for that. Both
compilers are able to close a GAP the old compilers never will in
functionality the OS has since the 2 last versions. Backward
compatibility to older versions is no need anymore since some newer
key applications are not working on the older versions.

Time goes on. It is time to go on.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
 
K

Keith Thompson

Herbert Rosenau said:
None of the bloody beginner who had understund 1% of C and what K&R
says about would ever write such [deleted] as you. So you've proven
yourself as having not even an idea what C is, to dumb to understund
it and lying around. [...]
You have never written a single procedure in C free of errors. You've
not even an idea what C is and would never learn it as you've proven
already.

Assuming that by "procedure" you mean "function", this is not entirely
true. I've seen at least one function written by spinoza1111 that is,
as far as I can tell, free of errors (though the style is horrendous).

There's plenty of basis for criticizing spinoza1111's C code;
exaggeration is not necessary.

[...]
So long you says that about yoursef you are 100% correct. If you means
somebody else who has at lest 20 hours experience in C you are a self
[deleted] liar.

spinoza1111 has said that he's no longer following this thread. You
are feeding a troll who isn't even sticking around to be fed. Please
don't waste your time and everyone's bandwidth flaming this person; he
may deserve it, but the rest of us don't.
 
K

Keith Thompson

Herbert Rosenau said:
I prefere C98 since I own a C98 compiler for my environment. Befor
that my C89 compiler (the one the developer of the OS had delivered in
1997 was already aware of inline as an well documented extension.

You mean C99, yes?
 
C

Chris Dollin

Keith said:
I probably would have if I'd read it before compiling it.

Here's the function you're probably talking about:
========================================
// Convert character to its numeric form
//
//
int char2Number( char chrInChar )
{
int intInCharValue = ( int )chrInChar;
int intZeroValue = ( int )'0';
if ( intInCharValue < intZeroValue
||
intInCharValue > ( int )'9' ) return -1;
return intInCharValue - intZeroValue;
}

I can't understand why this isn't written as the directly comprehensible:

int charToNumber( char ch )
{ return isdigit( ch ) ? ch - '0' : -1; }

which says what it means without complication. (Of course one needs to
include the relevant header.)
 
C

Chris Dollin

Chris said:
I can't understand why this isn't written as the directly comprehensible:

int charToNumber( char ch )
{ return isdigit( ch ) ? ch - '0' : -1; }

which says what it means without complication. (Of course one needs to
include the relevant header.)

.... and also to /cast to unsigned char/. Grrr. I keep forgetting that bit.
 
F

Frederick Gotham

Herbert Rosenau posted:

Will you crash your progam too when a user mistypes his password? Will
you crash your program only because the user has typed 2=0067!"/"!
instead of 2006/12/21? That is what your assert() above will do.


That's why we validate our input before passing it to our more efficient
functions.
 
D

Dave Vandervies

Bill Pursell said:
Assert also tells the maintenance programmer what
the original coder expected.

Along those lines, here's a question for those people who keep asking
for help studying for their interviews:

You are a maintenance programmer. After making a change in module foo,
you start getting assert failures in module bar at a point shortly after
a call into module foo.
What do you do?
(a) Ask the programmer who originally wrote both modules why the condition
is being checked
(b) Change your new code in module foo to not return values that cause
the assert to fail
(c) Comment out the assert in module bar, since it gets deactivated in
the release build anyways

I once spent a week looking for the cause of bad output that ended up
being the result of somebody choosing (c) instead of (b). I was Not
Impressed.


dave
 
R

Richard Bos

Along those lines, here's a question for those people who keep asking
for help studying for their interviews:

You are a maintenance programmer. After making a change in module foo,
you start getting assert failures in module bar at a point shortly after
a call into module foo.
What do you do?
(a) Ask the programmer who originally wrote both modules why the condition
is being checked
(b) Change your new code in module foo to not return values that cause
the assert to fail

Both (a) _and_ (b).

Richard
 

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top