Gosh! You are clever. And how can I know if the given string
is bigger than the buffer without at least trying to measure
the length?
By knowing its length already, of course.
int fn(char *str)
{
char tmpbuf[512];
/* Here I have to start scanning the string.
At least 511 bytes must be scanned before
I realize that the length of the string is bigger
than tmpbuf. For bigger buffers a bigger WASTE
*/
}
Is it /my/ fault if you have a badly designed programme? Where did
"str" come from? How did you create it? Did you define its length when
you did so?
To put you out of your misery, the app in question read strings into
fixed length buffers, padded them with blanks and null-terminated
them. Thus the strings were /always/ exactly N characters long, no
more and no less. This removed any need at all anywhere to calculate
how long the strings were, because we already knew.
Because you never know when software will change and a constant
becomes a variable...
Two points here
a) constants have nothing to do with it.
b) designing an application for a series of unknown future changes for
unguessable purposes by maintenance droids of unknown quality is both
inefficient and foolish.
I also strongly suspect you're not a follower of XP. They'd shoot you
for doing that sort of thing.
Ahh and it was slower because of the division by zero tests?
Yes. How do I know? I measured it. Next question.
I would like to see the data that supports that hypothesis.
Sure. Get yourself employed by my former employer, and you can look at
my project post-implementation report. Its in the files of the
Technology Dept somewhere.
With today's machines, a test for zero is so fast
And you've proved this beyond all doubt on Vax/VMS, Vax/OSF,
Sun/Solaris, Windows NT/PIII, all of which were targets.
that to slow
down a calculator so that a human being notices the tests must have
been done in an incredible fashion,
Or incredibly often. You apparently have no experience of numerical
pricing techniques either. Ever heard of monte-carlo simulation?
The point you miss is that security and efficiency are not mutually
exclusive, nor is one axiomatically more important than the other.
Again you generalise unacceptably.
This finishes it. You, you are not AN IDIOT!
I'm glad we agree I'm not an idiot. I know that of course.