ikegami is right that you can use
pack and
unpack create / read from structs. however, using pack() to write structs does not work portably, especially when you've got a struct made up of different-sized elements - AFAIK C compilers are allowed to switch elements in struct around, and anyway insert unused bytes to align elements depending on their type. IOW:
struct {
byte a;
long b;
}
may take up 6 bytes on a system with 4-byte integers and a 2-byte alignment requirement for integers. OTOH on a system with 4-byte aligned 4-byte integers, it might take up 8 bytes.
Ofcourse, there are modules to deal with all of this, a CPAN search gave me this (probably incomplete) list:
note -
I've not tested any of these and if none of them work, I know Inline::C does, but it's probably overkill for this application. Also, if you only need it to work on a specific system, you can hardcode the pack() template anyway (you might have to experiment to get the right one).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.