ABI array format

Regan Heath regan at netmail.co.nz
Wed Dec 19 05:08:58 PST 2007


Kenny B wrote:
> Commonly in C API's you will see something of the following:
> 
> size_t byte_chr(void* haystack, size_t len, char needle);
> 
> or
> 
> uint mc_hash(memcache *mc, char *key, size_t len);
> 
> I have never seen the pointer and length in reverse order. Why then, is
> the ABI for the arrays in reverse order...
> 
> (length, pointer)
> 
> I know this is a real long shot, but it'd be super awesome (and also
> break every %.*s in printf, if those were reversed). I could rewrite
> those API's to be
> 
> size_t byte_chr(void* haystack, string needle);
> 
> uint mc_hash(memcache *mc, string key);
> 
> and it'd be about 500 times more awesome.

Correct me if I'm wrong but the ABI for arrays is not set in concrete by 
the D specification.  Therefore any code which relies on the ABI of 
arrays is inherently a little bit evil.

I believe there was a proposal to change the ABI for arrays to:
   (start pointer, end pointer)

Something to do with iterator support, I have only a vague idea.  This 
change will kill the printf thing and also what you want to do above.

Regan



More information about the Digitalmars-d mailing list