Segfault City

P

pete

pemo said:
Andrew Poelstra wrote:

I followed the link,
but alas couldn't find any such comment from Richard.

You can google on the phrase "theft of intellectual property"
in comp.programming, to see how he responded
to seeing a posted corrected version of some of his code.
 
S

spinoza1111

Richard said:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.

Where? On your system? And are you sure you know how to set all those
fancy switches, dear Richard?

Seriously, a professional would say in as neutral a way as possible, so
as not to give unnecessary offense, what he found and why he thinks it
is wrong. But we knew you are a hack and not a professional.

Furthermore, to make a positive assertion as opposed to a snide and
actionably libelous negative assertion exposes the former, recursively,
to attack and this would threaten your dominance of this intellectual
slum.
(Actually, using my normal gcc switches, it doesn't even get past TP3, but

I didn't use the Gnu compiler with what I shudder to think might be
what you believe a normal combination of its switches. Given that C is
such a primitive language, the actual result of any one compile with
any one setting of the large numbers of switches provided by gcc is of
course going to be precise but not in general predictable for any one
program.

I used the free Navia compiler, instead, with default settings.

It's already obvious to me that you are at best a paraprofessional, who
seriously recommends C for new development. I'd hazard that your C
environment is that of a Mad Scientist:

I was working in the lab late one night
When my eyes beheld an eerie sight

I am certain that when you pull C code (that you can't write yourself)
from the Web, you have to fiddle with your elaborate installation to
make it work. Here, you libelously make vague assertions that somehow
this reflects on the code in question because you were wounded in your
sense of dominance of comp.programming in 2000.
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.)

Did it run? Note, again, that you make negative assertions rather than
positive contributions because your goal here is the same as your goal
with Herb Schildt: libeling people who threaten your shaky
self-confidence and self-esteem.
 
S

spinoza1111

Keith Thompson wrote:

....a fairly good analysis of the program and its bug, which was to use
strcat without necessarily having the memory for the output. This was
my bad, and thanks to Keith Thompson for pointing it out. I will
correct the program at the moderated site.

Yes, I'd used strcat in that way because I was returning to C after
several years. I'd posted the rather trivial code because I'd
developed it for a class precisely to get word of any bugs. However,
Richard Heathfield has chosen to embarass himself by starting an
unneeded flame war, which he's gonna lose.
Richard Heathfield said:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

This "teacher of C" demonstrates his prowess with a masterful display of

I taught C at Princeton and assisted Nash with it when I was using it
every day in the early 1990s. But when OO languages became available, I
abandoned it because it was impossible to manage large data structures
properly in this language (Richard H thinks it's possible, which only
indicates his limitations).

At the time this code was written I was out of money and starting a new
career in Hong Kong, and was thinking of returning to C in order to
develop as cheaply as possible. However, Microsoft has issued free
releases of C# and other languages, and I should have used C++ in this
example and others.

In fact, given that I'm so fucking smart :), my really stupid error in
using strcat into an unknown region that would cause a segment fault in
many cases (but didn't on my system) illustrates that C is inadequate
for new development.
Interesting. I just tried it myself. Copy-and-pasting the program
was tedious, but once I did that there were no line-wrapping errors.
Perhaps it's a function of which browser you use.

Har har har. Yeah, well, let's not confuse Richard, Keith.
Obviously the "//" comments won't work if you use strict C90 mode.

Oh **** me. Actually, comment prefixes are damned if you do and damned
if you don't. If I'd used balance slash asterisk, someone would have
complained here, because scoring geek points is so terribly important.

Yes, // are "new". They are also a sanity saver and I like them a lot.
With "gcc -g -std=c99 -pedantic -Wall -W -O3 sieve.c -o sieve", I got:

sieve.c: In function `string2Number':
sieve.c:64: warning: comparison between signed and unsigned
sieve.c: In function `main':
sieve.c:202: warning: int format, time_t arg (arg 2)

The first is a comparison between an int and the result of strlen();
assuming no strings longer than 2**31-1 characters (on my 32-bit
system), this bug shouldn't cause any visible symptoms. Likewise, I
left the second bug in place, since both int and time_t happen to be
32-bit signed integers on the system I'm using. (If I were actually
going to use the program, I'd fix both bugs first.)
Is this a result of -pedantic?

In C sharp these issues don't arise, because it doesn't make the error
of making length a separate type from a number.

I should probably have set a -pedantic switch in Navia to catch this
because I agree that warnings are bad.
I got a quick seg fault when I ran it, because of the following really
dumb statement:

printf( strcat(strcat("Sieve of Eratosthenes primes from least prime >= %d ",
"to greatest prime <= %d\n"),
"Sieve contains %d entries\n"),
MAX(intStart, 3),
intFinish,
intSieveLimit );

Using "-fwritable-strings" avoided the seg fault, but messed up the
output (obviously it was still invoking undefined behavior).

Yes, this is the real brain fart on my part. I'd gotten used to
concatenating constants in strings because modern compilers, as I point
out in my book, concatenate them at compile time (well, my book
compiler does, and it was recently written therefore modern). I
"unnecessarily" break up strings for readability (lines that don't
scroll off the right side of the screen) but my formatting ASSUMES
courier new or another monospaced font. I could use XML but it is not
WYSIWYG.
I changed the above to use string literal catenation rather than
strcat():

printf( "Sieve of Eratosthenes primes from least prime >= %d "
"to greatest prime <= %d\n"
"Sieve contains %d entries\n",
MAX(intStart, 3),
intFinish,
intSieveLimit );

I've never seen what looks like Rexx above. It appears to use the rexx
rule that two adjacent strings with no intervening op are joined by
implicit concatenation. Is this part of the C standard, and if so, what
standard?

[Note: since I'm a professional and Keith is being one too, I don't
say, you fucking idiot that statement is wrong. Let this be an example
unto ye because we are making actual progress here. We learn how
foolish it is to strcat when you don't know you have the memory, etc.]
With that change, the program seems to work (its failure to indicate
that 2 is prime seems to be an intentional design flaw rather than a
coding error).

An "intentional design flaw"? Whuzzat? I would never do such a thing.

I think we can trust nearly anybody to know that 2 is prime (whether 1
is seems to be questionable).
It's still a good example of ugly C (they're called argc and argv, not
intArgCount and strArgValues), and it could probably be written more

Nope, they are called what I called them. The abandonment of Hungarian
notation was a mistake.
clearly in no more than half the space, but it's not nauseatingly bad.

I am glad you did not throw up. I agree that it's bad and based on this
discussion I will fix the strcat problem.

The program was written in an hour for a class, and today I like to
publish everything I can publish to get as much feedback as possible. I
thank you for an excellent example of CONSTRUCTIVE criticism where you
take the chance of being recursively (or iteratively wrong).

Now, on to the flamewar with the trolls...
 
S

spinoza1111

Andrew said:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

Just out of curiousity, did you stumble upon that while Googling your own
name? I'm not accusing you of arrogance, but it's interesting that he
mentions and insults you specifically in his preamble.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.

Ooh. Segfault City. Where all bad programs go to die. :)
(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 stopped reading after the first function. I wasn't sure why he kept

Which disqualifies you from a technical discussion. Why are you
posting?
casting chars to ints, as though there wasn't implicit casting going on
by default. Then he tested for > '9', which made no sense to me. Realizing
that I wouldn't be able to trace that logic, I stopped.

It was a straightforward test for numerics. Again, are you qualified to
be in this discussion?

You stopped trying to understand things twice, so your opinion is
worth...what?
What, if anything, can it be guaranteed will be > '9' in standard C?

This isn't grammatical therefore I do not fully understand it. If you
are saying there is no character greater than 9, well I wish you all
the best in your future career. You'll need it.
 
R

Richard Heathfield

(e-mail address removed) said:
Seriously, a professional would say in as neutral a way as possible, so
as not to give unnecessary offense, what he found and why he thinks it
is wrong.

What I found: http://www.developerdotstar.com/community/node/291

Why I think it's wrong:

1) It doesn't survive past TP3.
2) If I hack it so it does, it segfaults.
3) A single glance at the code is sufficient to reveal the cause
of the segfault.
But we knew you are a hack and not a professional.

But the code *doesn't work*. You have an odd definition of "professional".
Furthermore, to make a positive assertion [...]

....I am positive, for example, that you should not be teaching people how to
write C programs.

I didn't use the Gnu compiler with what I shudder to think might be
what you believe a normal combination of its switches.

Might have been an idea to try it, even without the switches. Still.
Given that C is
such a primitive language, the actual result of any one compile with
any one setting of the large numbers of switches provided by gcc is of
course going to be precise but not in general predictable for any one
program.

Well, /my/ programs are predictable. Clearly, yours are a little more
exciting than that. You never know /when/ they'll segfault.

I used the free Navia compiler, instead, with default settings.

It's already obvious to me that you are at best a paraprofessional, who
seriously recommends C for new development. I'd hazard that your C
environment is that of a Mad Scientist:

My C environment is basically bash/vim/gcc/gdb/gprof. Fairly normal setup,
really.
I am certain that when you pull C code (that you can't write yourself)
from the Web, you have to fiddle with your elaborate installation to
make it work.

Why? If it's properly written in standard C, it'll work out of the box. And
if it isn't, why would I want to make it work? I'll just find something
that does (if, as you say, I can't write it myself).
Did it run?

If "Segmentation fault (core dumped)" was the output you were expecting,
then yes, it ran perfectly. :)
 
S

spinoza1111

Alf said:
* Richard Heathfield:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.

(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 );

It's evident from the introductory text that Edward isn't a C
practitioner (e.g., he mentions how he had to figure out the declaration
syntax for arrays) and is used to more object-oriented languages, and
the code, such as the above, makes it painfully evident that he doesn't
have anybody doing quality assurance of the code -- which, one is led
to believe, is used in some C.Sc. course.

Perhaps he'd be glad to receive some help about that?


CC: (e-mail address removed), which I'm assuming is Edward G. Nilges.

This is spinoza1111 who is Edward G. Nilges, author of Build Your Own
..Net Language and Compiler [and please, don't use C, thank you very
much.]

I was a daily C practitioner in the early 1990s and daily had to call
to mind things such as "don't strcat into an area where you don't have
the memory". For this reason, I assisted "a beautiful mind" with C.

I abandoned C shortly thereafter because each time I realized a new
deficiency, a new source of undefined behavior, I would write a
preprocessor macro or similar tool to encapsulate the cure.
Unfortunately, the Greek word for cure is also the word for poison, and
I realized after talking to my object-oriented Yi number one son that I
needed to learn OO, because the tool claptrap was more work than
solving problems.

The code isn't used in a class. It was used merely to give an example
to a math teacher where I work of the algorithm.

Yes, I would have appreciated a private email. But Richard seems to
like flame wars, and I am happy to oblige.

So now we have more data smog, a new thread called "segfault city",
because I WILL respond to libel.

It would be funny if it weren't so sad.

Richard has it seems a track record of leading vicious attacks by
Armies of Darkness on people who publish books other than himself. In
the 1990s, he conducted such an attack on Herb Schildt because Herb had
concealed some facts about C from the tyro in the interests of
TEACHING, something which bores Richard because it requires the TEACHER
to be something other than a narcissist.

Richard's delusion is that there is some sort of Platonic "C" and he is
its prophet. What there is is only praxis, and the language was so
primitively defined that it's not possible to write a correct compiler,
in the sense that the C community would ever agree that this is the
correct C compiler.

A language that permits aliasing in the way C permits aliasing is
*unteidscheidbar* undecidable all the way down. Whereas C# was
carefully designed to adhere not only to a syntax but to a runtime
standard defined by ECMA, as was Java, and it makes sense in these
languages to talk about the One Way.

I agree that Java libraries change the meaning of Java programs and
interact as do proteins with DNA. But the undecidability is
quantitatively less.

Richard joins the sad legion of people who mistake the contents of
their minds, their precise understanding of the Concept at a particular
time, with Absolute Truth.
 
R

Richard Heathfield

(e-mail address removed) said:
Yes, I'd used strcat in that way because I was returning to C after
several years.

That's what you said last time you posted some duff C, too, which was in
2002 or possibly 2003.
I'd posted the rather trivial code because I'd
developed it for a class precisely to get word of any bugs.

Those who claim to *teach* C should have a thorough understanding of the
language. That printf indicates that you don't even have a /basic/
understanding.

I taught C at Princeton and assisted Nash with it when I was using it
every day in the early 1990s.

Lots of employers will now be checking their C programmers' CVs to find out
whether they learned C at Princeton in the early 1990s.

By Nilges' own admission, the "assistance" he gave to John Nash consisted
IIRC of suggesting the use of a compiler that used 32-bit ints rather than
16-bit ints. He has been dining out on this "assistance" ever since.
But when OO languages became available, I
abandoned it because it was impossible to manage large data structures
properly in this language (Richard H thinks it's possible, which only
indicates his limitations).

<grin> Yeah, that's right - if people can manage large data structures
properly in C, then *obviously* they have limitations compared to those who
can't.

In fact, given that I'm so [elided] smart :), my really stupid error in
using strcat into an unknown region that would cause a segment fault in
many cases (but didn't on my system) illustrates that C is inadequate
for new development.

A good engineer doesn't blame the wheel when the real problem is the nut
behind it.
 
S

spinoza1111

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;
}
========================================

If something is < '0' or > '9', it's not a digit, and the function
returns -1 as an error indication.

On first glance, I assumed that something that size would convert a
string to an integer ("123" --> 123). Then I realized it only
converts a single character.

It's really impressive how ugly this manages to be without actually
being incorrect.

Mind of the beholder. You like short code. I find it easier to explain
longer identifiers.

But here, as opposed to your eariler post, you fall into the habit of
casting aspersions.

Why is code with short identifiers "ugly"?

The English language is also a world language. Nearly all world
programmers know English. Fewer use a standard set of abbreviations or
single characters in a fixed way: not even i always means "index".

I conclude that the best way to globally communicate the intent of an
identifier is to, within reason, spell it out. intCharValue is the
value of the character. It's an int. The Hungarian complements the
English nicely...in my opinion, and, I'm probably right.

Not sure what is "ugly" about trying to communicate, not just to
Amerikkkan geeks but to world programmers.

Not sure what is "beautiful" about adopting the all-too-ingrained
habits of the lead lawn troll in some little "community" and repeating
his mistakes. I'm well aware that "standard" C style uses argc and argv
but the letter c simply is too vague to mean "count".

Indeed, if you use what you call a "beautiful" style, you end up with a
Mandarin style. Ancient Chinese texts are incomprehensible, in my
experience working in China, to well-educated Chinese who had a
technical and scientific education in the mainland, yet my English
students in Hong Kong educated with traditional characters and ancient
texts persist in finding simplified Chinese characters and a modern
style "ugly" even though it does in fact a better job in communicating.

Richard the Heathfield may be a sort of C mandarin, insisting in the
teeth of the facts that his style is "clear and beautiful".

Of course, I might be the mandarin. I'm not communicating with you with
full success. But, you understood the intent of the code.
 
R

Richard Heathfield

(e-mail address removed) said:
Which disqualifies you from a technical discussion.

No, it doesn't, because he can always go back and read it if he wishes. And
he is certainly qualified to discuss the part he has read.
Why are you posting?

Why are you?
It was a straightforward test for numerics.

No, it wasn't even remotely straightforward. It was unnecessarily verbose.

This would be a straightforward test for numerics:

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

If you think that's too obfuscated, here's another, which I don't like very
much as it trades structural elegance for simplicity, but it /is/ simple:

int to_digit(int ch)
{
if(isdigit((unsigned char)ch))
{
return ch - '0';
}
return -1;
}

Again, are you qualified to be in this discussion?

As much as you are, and probably more.
You stopped trying to understand things twice, so your opinion is
worth...what?

Plenty. What he's saying is that your code is unnecessarily obscure and
difficult to read. That's the mark of a bad programmer, unless your intent
is to win the IOCCC.
This isn't grammatical therefore I do not fully understand it. If you
are saying there is no character greater than 9, well I wish you all
the best in your future career. You'll need it.

C offers no guarantee that there is any character with a code point higher
than '9'. In EBCDIC, the code point of '9' is 249, so there are just six
characters (none with well-defined interpretations) with higher code
points. So Andrew's point is perfectly valid. It was also sufficiently
grammatical than I could understand it.
 
S

spinoza1111

Keith said:
Richard Heathfield said:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.

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

Interesting. I just tried it myself. Copy-and-pasting the program
was tedious, but once I did that there were no line-wrapping errors.
Perhaps it's a function of which browser you use.

If you try the printer friendly version of the page copy and pasting
is easy with no line-wrapping.
I got a quick seg fault when I ran it, because of the following really
dumb statement:

printf( strcat(strcat("Sieve of Eratosthenes primes from least prime >= %d ",
"to greatest prime <= %d\n"),
"Sieve contains %d entries\n"),
MAX(intStart, 3),
intFinish,
intSieveLimit );

Using "-fwritable-strings" avoided the seg fault, but messed up the
output (obviously it was still invoking undefined behavior).

I changed the above to use string literal catenation rather than
strcat():

printf( "Sieve of Eratosthenes primes from least prime >= %d "
"to greatest prime <= %d\n"
"Sieve contains %d entries\n",
MAX(intStart, 3),
intFinish,
intSieveLimit );

His use of strcat was very puzzling for me. Even if he doesn't know
that the compiler will concatenate strings why not use multiple
printf's ? The use of nested strcat's make it a lot less readable even
if it was working.

I know that a good compiler will not only concatenate literal strings
it will evaluate constant expressions at compile time,because my quick
basic compiler does this. What puzzles me is the implication elsewhere
that if two strings appear, either adjacently or on separate lines,
they will be magically concatenated as in rexx. You may be right.

The nested strcats suck because I believe I missed the fact that no
space was allocated for them.
I haven't tried compiling it but I tried to read it and understand it.
After
a while I gave up. His general verbosity and use of Hungarian notation
in particular made it unreadable for me. Based on what I could
understand
I doubt that it actually implements Eratosthenes's sieve. Here's a

It did on my system. I posted it for critique and have here received
some useful information from Keith Thompson. But Heathfield posted it
here in bad faith and maliciously in order to get a sequence of posts
that make negative claims without constructively pointing out errors in
such a way that the criticiser could be criticised.

Par for the course on comp.whatever in usenet.
programme which does:

#include <stdio.h>
#define LIMIT 1000

int main() {
int sieve[LIMIT+1] , i , j ;

for (i=2 ; i<=LIMIT ; i++) sieve=1 ;

for (i=2 ; i <= LIMIT/2 ; i++) {
for (j=2 ; i*j <= LIMIT ; j++) {
sieve[i*j] = 0 ;
}
}
for (i=2 ; i<=LIMIT ; i++) {
if (sieve) printf("%d\n",i) ;
}
}

Spiros Bousbouras
 
P

pemo

Keith Thompson wrote:

It's still a good example of ugly C (they're called argc and argv,
not intArgCount and strArgValues), and it could probably be written
more

Nope, they are called what I called them. The abandonment of Hungarian
notation was a mistake.


I think Keith's comment on argc/argv is right, i.e., using argc/argv follows
the rule of keeping 'the least possible surprise value' to a minimium. It's
what's 'expected' - I feel that there's no good reason for changing the
parameter names, and doing so will only cause confusion somewhere down the
line.

On Hungarian Notation, a few years ago [oh, now that I come to think about
it, that's quite a few years ago] I would have agreed with you - I used HN
all of the time, and liked it once I got used to it [I *had* to adopt their
use where I worked].

However, IMHO, modern development environments makes their use redundant -
now, if you want to know the type-of-something, its storage-class, or where
it's declared/defined - you simply use some shortcut/gesture built into the
development environment and you'll get all the information you need. And
that's great - this kind of feature, when used with meaningful names makes
code more readable [more easily parsable, and kinder on the eye]. In fact,
in dropping them, it might also make one think just a little harder about
the 'usage' part of any name used?
 
S

spinoza1111

Richard said:
Andrew Poelstra said:
[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

Just out of curiousity, did you stumble upon that while Googling your own
name? I'm not accusing you of arrogance,

...just of self-indulgence. Yes, I was actually looking for a specific Terry
Pratchett quote. I knew it was on a page of quotations that /also/ quoted
something by me, but that's all I could remember, so I googled for my name
+ quote and Google showed me:

Wayne's World of C Code (The Sieve of Eratosthenes) | developer ...
[Richard Heathfield and his team have some good advice in his book, ... I
wish I could quote the whole column (or link to it--it's not available
online), ...
www.developerdotstar.com/community/node/291 - 59k - Cached - Similar pages

which looked promising, but alas, turned out to be junk after all.

I stopped reading after the first function. I wasn't sure why he kept
casting chars to ints, as though there wasn't implicit casting going on
by default. Then he tested for > '9', which made no sense to me. Realizing
that I wouldn't be able to trace that logic, I stopped.

What, if anything, can it be guaranteed will be > '9' in standard C?

UCHAR_MAX + 1.0, I think, although if you have really amazingly colossal
chars you might manage to break it.

Do enlighten us, Richard. I was testing the character 9 which isn't the
highest value character, in ascii or unicode or even ebcdic. Has your
favorite standard defined '9' as the perfect character? Alert the
media!
 
R

Richard Heathfield

(e-mail address removed) said:
Do enlighten us, Richard. I was testing the character 9 which isn't the
highest value character,

The C Standard does not guarantee that. It's a minor point.
in ascii or unicode or even ebcdic.

Curiously, it /is/ the highest EBCDIC character with a well-defined meaning,
although it is certainly true that there are half a dozen slots above it.
Has your
favorite standard defined '9' as the perfect character?

No, but neither has it guaranteed that '9' is not the highest character.
 
M

Mark McIntyre

[X-posted, and followups set]

I found something interesting on the Web today, purely by chance.

It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.

http://www.developerdotstar.com/community/node/291

I'm assuming you remember Edward G Nilges from his brief habitation
under a bridge here in CLC?


--
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
 
S

spinoza1111

Richard said:
(e-mail address removed) said:


No, it doesn't, because he can always go back and read it if he wishes. And
he is certainly qualified to discuss the part he has read.


Why are you?

Because you're engaged in a campaign of personal destruction as you
were with Schildt.
No, it wasn't even remotely straightforward. It was unnecessarily verbose.

This would be a straightforward test for numerics:

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

If you think that's too obfuscated, here's another, which I don't like very
much as it trades structural elegance for simplicity, but it /is/ simple:

int to_digit(int ch)
{
if(isdigit((unsigned char)ch))
{
return ch - '0';
}
return -1;
}



As much as you are, and probably more.

Expressed fairly enough.
Plenty. What he's saying is that your code is unnecessarily obscure and
difficult to read. That's the mark of a bad programmer, unless your intent
is to win the IOCCC.

No, the mark of a bad programmer is inability to think outside the
particular set of chosen inputs and your insistence that C is still
usable for new development.
C offers no guarantee that there is any character with a code point higher
than '9'. In EBCDIC, the code point of '9' is 249, so there are just six
characters (none with well-defined interpretations) with higher code
points. So Andrew's point is perfectly valid. It was also sufficiently
grammatical than I could understand it.

OK, this is complete nonsense. Are you pulling my leg?

You read in the standard that "C offers no guarantee with a code
point..."

But it MEANS that there CAN be. Can you read?

And to use EBCDIC, a completely obsolete encoding, obsoleted by ASCII
and then international 16 bit encoding...the mind boggles!

In ASCII, for which nearly all C code is written, the letters follow
the numbers! If the user enters A your "correct code" breaks?

[The "standard" may require the C runtime to treat the digits as
following the characters. The fact is that real compilers don't, and
use the encoded value. What this illustrates is the UNUSABILITY of the
standard, and consequently that it is extremely unwise, to the level of
professional malpractice, to recommend C for new development, as you
appear to.]

Are you for real? And you are sitting on your fat ass telling me I
don't know how to program?

But then you say that there are "just 6 characters" as if the small
number of characters makes it probable that your code won't break!

"My program is standard C, therefore the user has no right to send
characters with t a value higher than 9" is the zenith of arrogance.

And you use this as a reason for presenting code which BREAKS if there
IS a code point after all (c - 0 with no test for greater than 9)????

This is worse than I thought.

You seem to be using C on an IBM mainframe with the SAS compiler, and
pompously talking about C based on a misreading of the standard!

And if your compiler runs on an ASCII system, it has to jiggle
characters at runtime to make sure 9 is the "last" character. And C is
an "efficient" language?

Without being even aware that given aliasing, C can't be standardized
in a modern sense?

And icing on the cake..."it was also sufficiently grammatical THAN I
could understand it".

Do respond. I need a laugh and it seems you are ... well, not awake,
but posting. Are you drunk? Are you stoned?
 
S

spinoza1111

Richard said:
(e-mail address removed) said:

The C Standard does not guarantee that. It's a minor point.


Curiously, it /is/ the highest EBCDIC character with a well-defined meaning,
although it is certainly true that there are half a dozen slots above it.

And I should worry about EBCDIC? It is true, based on my experience in
teaching SAS C in 1989 that there are "C" compilers where you MIGHT get
away with your nonsense. The code for these compilers is NONPORTABLE to
ASCII machines as-is.

Which shows that in terms of modern languages there is literally no
such thing as the C programming language. It is an illusion.

And yet based on it you are conducting a campaign of personal and
professional libel.
No, but neither has it guaranteed that '9' is not the highest character.

Oh, ok, it MIGHT be the highest character therefore your wonderful code
can ignore the possibility (which the "might be" implies) that it is
not?
 
S

spinoza1111

pemo said:
Nope, they are called what I called them. The abandonment of Hungarian
notation was a mistake.


I think Keith's comment on argc/argv is right, i.e., using argc/argv follows
the rule of keeping 'the least possible surprise value' to a minimium. It's
what's 'expected' - I feel that there's no good reason for changing the
parameter names, and doing so will only cause confusion somewhere down the
line.

The problem is that the use of a nonstandardizable and aliasing
language causes the confusion.

No generalization can be made world wide concerning the universality of
argc and argv. I've maintained code in Red China, and I am only amused
by these people in the USA who make unsupported generalizations about
what is "meaningful".

It's in the mind of the beholder. My OO style is delegation centric and
doesn't use enumerators (I need to change), I had to maintain code that
was inheritance and enum centric. I didn't charge the author with
incompetence, instead I endeavored to find out good reasons for change.
On Hungarian Notation, a few years ago [oh, now that I come to think about
it, that's quite a few years ago] I would have agreed with you - I used HN
all of the time, and liked it once I got used to it [I *had* to adopt their
use where I worked].

However, IMHO, modern development environments makes their use redundant -

At the time I wrote the code, I was thinking of coding in India on a
hand-cranked laptop without the power for a "modern development
environment".

In Hong Kong, a "modern development environment" costs 8000.00 HK
dollars. Why should be substitute money for thought and a
self-discipline?
now, if you want to know the type-of-something, its storage-class, or where
it's declared/defined - you simply use some shortcut/gesture built into the
development environment and you'll get all the information you need. And
that's great - this kind of feature, when used with meaningful names makes
code more readable [more easily parsable, and kinder on the eye]. In fact,
in dropping them, it might also make one think just a little harder about
the 'usage' part of any name used?

You may be missing the need for a structure in the name. The HN keeps
the name from being formally or informally reserved. It partitions the
"name space" into exclusive classes.
 
B

Bill Pursell

Are you for real? And you are sitting on your fat ass telling me I
don't know how to program?

It is evident from your code that you are not proficient with C,
so it is not necessary for Richard to comment on your ability.
However, your continual insistence that C is not suitable for new
development is incredibly annoying. C is certainly not
suitable for you, and you should either stop using it
or try to learn it. You clearly dislike Richard, but you
could probably learn a lot from him.
 
M

Malcolm

Because you're engaged in a campaign of personal destruction as you
were with Schildt.
If you are going to argue that C is unusable for new development, on
comp.lang.c, then you can expect some pretty robust disagreement.
No, the mark of a bad programmer is inability to think outside the
particular set of chosen inputs and your insistence that C is still
usable for new development.
A function in C only has to be well-behaved for legal inputs. That's a
weakness in the language. Other languages have other weakness.
OK, this is complete nonsense. Are you pulling my leg?

You read in the standard that "C offers no guarantee with a code
point..."

But it MEANS that there CAN be. Can you read?
What it means is that the code

char ch = '9' + 1;

is allowed to break on a conforming implementation.
Now this isn't a particularly sensible rule, since as you say all the world
uses ASCII. But it is the rule. Code that doesn't adhere to it is not
strictly portable.

There are certain problems in converting between characters and the
underlying integers. Generally you want to keep a distinction between
natural language letters and integers, but for some purposes we do need a
number assciated with a letter, for instance when using letters for
indexing. In practise C does a reasonable job of this, though the theory is
a bit shaky.
 

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,218
Latest member
JolieDenha

Latest Threads

Top