N
Name and address withheld
I am trying to understand how ustr (http://www.and.org/ustr/design)
works. Its a string-handling library for C, and it stores strings in the
following struct, called a "magic struct"
struct Ustr
{
unsigned char data[1];
/* 0b_wxzy_nnoo =>
*
* w = allocated
* x = has size
* y = round up allocations (off == exact
* allocations)
* z = memory error
* nn = refn
* oo = lenn
*
* 0b_0000_0000 = "", const, no alloc fail, no mem
* err, refn=0, lenn=0 */
};
It seems to me that a struct Ustr will only occupy 1-byte of memory, so
how can it contain even a simple pointer to char??? What's happening
here?
works. Its a string-handling library for C, and it stores strings in the
following struct, called a "magic struct"
struct Ustr
{
unsigned char data[1];
/* 0b_wxzy_nnoo =>
*
* w = allocated
* x = has size
* y = round up allocations (off == exact
* allocations)
* z = memory error
* nn = refn
* oo = lenn
*
* 0b_0000_0000 = "", const, no alloc fail, no mem
* err, refn=0, lenn=0 */
};
It seems to me that a struct Ustr will only occupy 1-byte of memory, so
how can it contain even a simple pointer to char??? What's happening
here?