float *vector() function


toasty
05-19-2003, 10:40 AM
Just a small question about the vector function given in nrutil.c on page 943 of NRC, second edition.

What is the purpose of NR_END? Memory for nh-nl+1+1 is allocated, while a vector which starts at nl and ends at nh uses nh-nl+1 cells. It seems to me that 1 more element is being allocated than necessary.

I have had times however, when having a program which crashes under weird circumstances, with such malloc/calloc routines, that sometimes making the vectors a bit bigger (sometimes by 1) alleviates the crashing problem (probably because of a bug somewhere I was unable to find), I don't suppose that this is the reason you are doing it here?

Bill Press
05-19-2003, 10:29 PM
Toasty,

This is explained in detail in the text at the bottom of page 940 and continuing onto the top of page 941. In brief, it is to be sure that the pointer value returned for a unit-offset array is guaranteed to be representable in the ANSI C standard. We are not aware of any compiler or machine that actually needs NR_END to be 1 (as opposed to zero), but you never know.

Cheers,
Bill P.

toasty
05-19-2003, 10:39 PM
Ah, thanks, I should have read that beginning portion more carefully. I am wanting to modify these routines and want to make sure I can safely leave out the NR_END. I think I can.

Thanks again.

Originally posted by Bill Press
Toasty,

This is explained in detail in the text at the bottom of page 940 and continuing onto the top of page 941. In brief, it is to be sure that the pointer value returned for a unit-offset array is guaranteed to be representable in the ANSI C standard. We are not aware of any compiler or machine that actually needs NR_END to be 1 (as opposed to zero), but you never know.

Cheers,
Bill P.