Packing C structs from PHP -


i've played around pack() longer i'd admit, , accidentally stumbled across data structure alignment. there "good" way create c structures within php , account these padding bytes?

i know can use "x" inject null bytes, how determine these go , how many use programmatically?

along same lines, of these methods better modeling char foo[10] array?

$struct = pack('a9x', $string); // vs. $struct = pack('a10', substr($string, 0, 9)); 

i believe both accomplish same thing, i'm not sure of potential pitfalls.

what try achievable, highly dangerous. let me explain:

  • php code largely independant hardware/os/c runtime runs on
  • (portable) c source code also
  • the compilation/linking/loading process of c binary definitly not (especially if leave padding/packing issues compiler)

now try in php partial reimplementation of compilation/linking/loading process, without reliable mechanism determine adapt environment.

i recommend 1 of 2 imho more reliable ways this:

  • write php extension (this rather easy), structure-dependant stuff you, including headers c program. if compile on target system (or 1 equal environment) not run troubles above
  • chose another, higher level mechanism communicate: have used sysv messages similar requirement, there plenty of ways go.

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -