[sv-bc] 0002900: Associative array should consider the context of an lvalue to create an entry

From: Rich, Dave <Dave_Rich_at_.....>
Date: Fri Oct 09 2009 - 11:20:31 PDT
Submitted as Mantis 2900

 

Sec 7.8 currently says:

 

Array elements in associative arrays are allocated dynamically; an entry
is created the first time it is written.

 

I believe it needs to be further clarified: 

 

"An entry for an associative array element shall be allocated the first
time it appears where an lvalue is required."

 

Some examples to illustrate where an lvalue is required, but before a
write to the entry has completed

 

     int a[int];

 

     typedef struct { int x,y; } S;

     S   b[int];

 

     f(a[i]);      // where the formal is "ref int"

     a[i]++;

     b[i].x = 5;

 

The latter 2 are conceptually related to the "f" example if a[i]++ is
written as:

    increment(a[i]);

with increment defined as

    function int increment(ref int val); 

        val = val + 1;

        return val;

    endfunction

    

then one could argue that the "a[i]" actual is just a read of the array
and that the update occurs to a temp that has the default value.

 

Similarly with b[i].x = 5 -- is written as:

    temp = b[i];   // reads the default

    temp.x = 5;    // partial write

    b[i] = temp;   // write to the entry

 

 

Dave Rich

 

 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Oct 9 11:22:17 2009

This archive was generated by hypermail 2.1.8 : Fri Oct 09 2009 - 11:25:24 PDT