----Original Message----
>From: Georg Bauhaus
>Sent: 15 July 2005 14:21
> You can have both, correctness and uninitialised local
> variables. For an impression of the difference in performance,
> and for a way to ensure correctness, I tried this
> (switch register/volatile in the declaration lines in comp
> and r to see the effects).
I didn't get that far. Before the first call to comp the program has
already accessed uninitialised memory:
> int main()
> {
> short buffer[BUFFER_SIZE];
> int result;
>
> assert(ITERATIONS > 0);
So far, so good. Declare some uninitialised storage.
>
> for (int runs = 0; runs < ITERATIONS; ++runs) {
First time round, runs = 0;
> result = r(buffer, BUFFER_SIZE);
Call function 'r'.
> /* pre: a has elements, that is hi > 0. Frequently called */
> int r(short a[], size_t hi)
> {
> //register int x, y, z;
> volatile int x=1, y=2, z=3;
x=1, y=2 and =3. hi = BUFFER_SIZE and a[] is uninitialised.
>
> assert(hi > 0);
Still good...
> for (size_t c=0; c < hi + 2; ++c) {
> if (a[c]) {
Uninitialised variable access. Boom. *NOT* correct.
In what sense of the word 'correct' do you claim this example is correct?
cheers,
DaveK
--
Can't think of a witty .sigline today....