Re: A note on personal corruption as a result of using C



Visual Basic (!) and most other languages that have for got it right,
whereas C got it wrong, because the for loop in C is just another way
of coding a while with sugar

1. No. A for() in C is equivalent to FOR NEXT in VB.
You are so uniformed

int i, j;

for (i = 1; i < 1000; i *= 5) { } // Hey multiplying by 5
each time round
for (i = 1024; i > 1; i /= 2) { } // Hey dividing by 2 each
time round
for (i = 1; i < 100; i <<= 2) { } // Bitshifts
for (i = 1024, j= 1; i > 1 && j < 100; i /= 2, j += i) { } // two
operations each time round
for (i = 1; i < 100;) { i++; } // no 3rd section,
increment within

None of those can be in Microsoft BASIC. The FOR NEXT can _ONLY_ addition
and subtraction and it cannot manage 2+ variables at once. C can.
Ha ha, what a limitation.

for() is more general than while().

2. while (i < 10)
is equivalant to
for (; i< 10 ; )
but only for() has room for initialisation section and increment section

3. for ( ;; ) is forever.

4. Finally, continue does not work the same way in while() compare to for().
continue will do the optional increment section in for() before evaluating
the loop evaluation condition, continue in while() jumps straight to the
loop evaluation condition.
That means if you want some increment at the bottom of a while() loop to
happen before the loop evaluation condition, you cant use continue whereas
you can with for() if the increment is in the 3rd section.

: as in the case of the ugly replication of str*** functionality in
mem*** functions, a mistake is covered up

It isnt a mistake, it is design constraint.
C strings werent designed for binary data with embedded '\0''s
C strings work reasonably well for small and moderate length data.
They dont work so well for strings which are several megabyte in length
which might be better served by strings where the length is stored.
But there is no free lunch here : the length has to be stored, which takes
space and also maintained as an invariant (equal to length of characters
stored).
Everybody in this newsgroup recognises *tradeoffs* (like space versus time,
deciding things through data rather than code) - except you.

The things I dislike about the C library are

gets() - absolutely no way of using this safely, use fgets()
strncpy() - inefficent may append many unncessary '\0''s or alternatively no
'\0' (dangerous)
strtok() - would have preferred the state stored outside (better for
mutithreading - but this wants no the menu when K&R designed it)

with duplication of effort, a duplication that creates duplication of
mental effort.

You find your brain cells oveheating with the effort Nilges?

This is to assume...

[snip] Nilges pontificating hot air.

Stephen Howe


.