www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22250] New: ImportC: Array subscripts do not comply with C

https://issues.dlang.org/show_bug.cgi?id=22250

          Issue ID: 22250
           Summary: ImportC: Array subscripts do not comply with C
                    standard.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxhaton gmail.com

As per (C11) 6.5.2.1: "A postfix expression followed by an expression in square
brackets [] is a subscripted
designation of an element of an array object. The definition of the subscript
operator []
is that E1[E2] is identical to (*((E1)+(E2)))."

As such the following should compile: 
---
int main()
{
    char staticArray[256];
    char squoze = 2[staticArray];
}
---
currently fails with 

Error: cannot use `[]` operator on expression of type `int`

I doubt much C code actually uses this but supporting it could prove a useful
exercise in supporting C semantics properly rather than kind of bullying a
valid C parse into the dmd AST.

--
Aug 29