Re: function pointers



Michal Nazarewicz <mina86@xxxxxxx> wrote in comp.lang.c:

Forgot about "()" and to be precise you should check if user_input is
>= 0 and <= 4.

The only redudant checks I use in my programs are asserts. If the input to a function should be between 0 through 4, then I'll document it and say that the behaviour is undefined if the input's out of range. Of course though, I'll still make liberal use of assert.

/* MyFunc

input : Number between 0 through 4
Behaviour is undefined if out of range
*/

void Func(unsigned const i)
{
assert(i < 5);

int arr[5];

arr[i] = 6;
}

--
Tomás Ó hÉilidhe
.