I've played around with pack()
for longer than I'd like to admit, and accidentally stumbled across data structure alignment. Is there a "good" way to create C structures from within PHP and account for these extra padding bytes?
I know that you can use "x" to inject NULL bytes, but how do you determine where these go and how many to use programmatically?
Along the same lines, which of these methods is better for modeling a char foo[10]
array?
$struct = pack('a9x', $string);
// vs.
$struct = pack('a10', substr($string, 0, 9));
I believe they both accomplish the same thing, but I'm not sure of any potential pitfalls.