digitalmars.D - ABI array format
- Kenny B (15/15) Dec 19 2007 Commonly in C API's you will see something of the following:
- Regan Heath (9/31) Dec 19 2007 Correct me if I'm wrong but the ABI for arrays is not set in concrete by...
- Jascha Wetzel (3/6) Dec 19 2007 Luckily the D specs didn't make the same mistake as the C++ specs did by...
-
Regan Heath
(3/10)
Dec 19 2007
Shows what I know.
- Sean Kelly (7/14) Dec 19 2007 Now if only GDC complied to the D ABI :-)
- Jascha Wetzel (3/9) Dec 20 2007 indeed, maybe when llvmdc gets to the next level, this topic becomes
- Walter Bright (3/7) Dec 19 2007 It was so you could pass a D string to printf and print using the %.*s
- Kenny B (6/14) Dec 19 2007 that's what I figured. printf has almost completely been phased out. is
- Walter Bright (4/16) Dec 19 2007 I recommend treating array contents as an opaque type, and call the C
- Janice Caron (6/9) Dec 19 2007 Obviously, I agree with that. But...
- Walter Bright (2/13) Dec 19 2007 ABIs are for things like link compatibility between implementations.
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. Thanks for listening, Kenny
Dec 19 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
Dec 19 2007
Regan Heath wrote: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.Luckily the D specs didn't make the same mistake as the C++ specs did by *not* specifying the ABI: http://www.digitalmars.com/d/abi.html
Dec 19 2007
Jascha Wetzel wrote:Regan Heath wrote:Shows what I know. <g> Thanks.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.Luckily the D specs didn't make the same mistake as the C++ specs did by *not* specifying the ABI: http://www.digitalmars.com/d/abi.html
Dec 19 2007
Jascha Wetzel wrote:Regan Heath wrote:Now if only GDC complied to the D ABI :-) By the way, the ABI really should be expanded to encompass x86-64 and ideally exception handling as well. As it is, the ABI really isn't sufficient to allow code built by one compiler to be linked to code built by another compiler, which is really the point of an ABI, isn't it? SeanCorrect 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.Luckily the D specs didn't make the same mistake as the C++ specs did by *not* specifying the ABI: http://www.digitalmars.com/d/abi.html
Dec 19 2007
Sean Kelly wrote:Now if only GDC complied to the D ABI :-) By the way, the ABI really should be expanded to encompass x86-64 and ideally exception handling as well. As it is, the ABI really isn't sufficient to allow code built by one compiler to be linked to code built by another compiler, which is really the point of an ABI, isn't it?indeed, maybe when llvmdc gets to the next level, this topic becomes more relevant, especially x86-64.
Dec 20 2007
Kenny B wrote:Why then, is the ABI for the arrays in reverse order... (length, pointer)It was so you could pass a D string to printf and print using the %.*s format.
Dec 19 2007
Walter Bright wrote:Kenny B wrote:that's what I figured. printf has almost completely been phased out. is it possible that this format can be reversed when printf is a thing from the past? Thanks man, KennyWhy then, is the ABI for the arrays in reverse order... (length, pointer)It was so you could pass a D string to printf and print using the %.*s format.
Dec 19 2007
Kenny B wrote:Walter Bright wrote:I recommend treating array contents as an opaque type, and call the C functions using array.ptr and array.length. That way, you'll be insured against implementation changes.Kenny B wrote:that's what I figured. printf has almost completely been phased out. is it possible that this format can be reversed when printf is a thing from the past?Why then, is the ABI for the arrays in reverse order... (length, pointer)It was so you could pass a D string to printf and print using the %.*s format.
Dec 19 2007
On 12/20/07, Walter Bright <newshound1 digitalmars.com> wrote:I recommend treating array contents as an opaque type, and call the C functions using array.ptr and array.length. That way, you'll be insured against implementation changes.Obviously, I agree with that. But... I recommend changing the documentation on http://www.digitalmars.com/d/abi.html, which states in black and white not only that the layout is not opaque, but tells you what's inside it. Folk can hardly be blamed for relying on that.
Dec 19 2007
Janice Caron wrote:On 12/20/07, Walter Bright <newshound1 digitalmars.com> wrote:ABIs are for things like link compatibility between implementations.I recommend treating array contents as an opaque type, and call the C functions using array.ptr and array.length. That way, you'll be insured against implementation changes.Obviously, I agree with that. But... I recommend changing the documentation on http://www.digitalmars.com/d/abi.html, which states in black and white not only that the layout is not opaque, but tells you what's inside it. Folk can hardly be blamed for relying on that.
Dec 19 2007