note
BrowserUk
<blockquote><i></i></blockquote>
<p>I don't see anything particularly wrong with your approach, but I have a few thoughts:
<ol><li><c>buf[i] = (int)SvNV(*elem);</c>
<P>buf[] is define as unsigned char, but you're retrieving reals, and casting them to signed ints?
</li><li>If you are going to pass in an array of ints or reals, you should really check they will fit into an unsigned char or cast appropriately to ensure they will.
<P>Maybe that should be <C>buf[i] = (unsigned char)SvNV(*elem);</c> or even <c>buf[i] = (unsigned char)SvUV(*elem);</c>
</li><li><blockquote><i>I'll be passing the char buffer and len to an external C function.</i></blockquote>
<P>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?
<P>That way you cannot be passed out of range values so don't have to deal with them.
</li></ol>
<div class="pmsig"><div class="pmsig-171588">
<hr />
<font size=1 >
<div>With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'</div>
<div>Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.</div>
<div>"Science is about questioning the status quo. Questioning authority". [http://www.theregister.co.uk/2016/11/02/complexity_in_it/|The enemy of (IT) success is complexity.]</div>
<div>In the absence of evidence, opinion is indistinguishable from prejudice. </div>
</font>
</div></div>
1180088
1180088