I don't see anything particularly wrong with your approach, but I have a few thoughts:
buf[] is define as unsigned char, but you're retrieving reals, and casting them to signed ints?
Maybe that should be buf[i] = (unsigned char)SvNV(*elem); or even buf[i] = (unsigned char)SvUV(*elem);
I'll be passing the char buffer and len to an external C function.
Perl's string scalars can hold any unsigned char value, and carry their length, so why not just pass the pointer and length from a scalar argument?
That way you cannot be passed out of range values so don't have to deal with them.
In reply to Re: Is this a sane/safe way to pass an aref into a C function?
by BrowserUk
in thread Is this a sane/safe way to pass an aref into a C function?
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |