suppose i'm writing function takes float a[]
, offset, array, , returns element @ offset. reasonable use signature
float foo(float* a, off_t offset);
for it? or off_t
relevant offsets in bytes, rather pointer arithmetic aribtrary element sizes? i.e. reasonable a[offset]
when offset of type off_t
?
the gnu c library reference manual says:
off_t signed integer type used represent file sizes.
but doesn't tell me much.
my intuition answer "no", since actual address used in a[offset] address of + sizeof(float) * offset , "sizeof(float) * offset" off_t
, , sizeof(float) size_t
, , both constants 'dimensions'.
note: offset might negative.
is there reason why don't use int
? it's default type integral values in c++, , should used unless there reason not to.
of course, 1 reason might overflow. if context such end large arrays, might want use ptrdiff_t
, defined (in c , c++) type resulting subtraction of 2 pointers: in other words, guaranteed not overflow (when used offset) types size greater 1.
Comments
Post a Comment