Array indexing/offset inline asm ambiguity
John Colvin
john.loughran.colvin at gmail.com
Sat Mar 16 18:46:49 PDT 2013
On Sunday, 17 March 2013 at 00:24:16 UTC, David Nadlinger wrote:
> Hi all,
>
> Another installment in the »What does the following function
> return« series:
>
> ---
> int[2] foo() {
> int[2] regs;
> asm {
> mov regs[1], 0xdeadbeef;
> }
> return regs;
> }
> ---
>
> If you answered [0, 0xdeadbeef], then congratulations: You fell
> into exactly the same trap as Martin Nowak and I did in
> https://github.com/D-Programming-Language/druntime/pull/426,
> without any of the other reviewers noticing either.
>
> The issue is that in an inline asm block, regs[1] is actually
> equivalent to 1[regs] or [regs + 1] and evaluates to an address
> one *byte* after the start of regs, not one element as it does
> everywhere else.
>
> In my opinion, this is completely counterintuitive and a source
> of bugs that could easily be prevented by the language. But
> Walter seems to think this issue not worth addressing:
> http://d.puremagic.com/issues/show_bug.cgi?id=9738
>
> What do you think?
>
> Thanks,
> David
D syntax should have D semantics, even in inline asm. (where that
syntax does not conflict with the asm syntax of course)
More information about the Digitalmars-d
mailing list