Opened 23 months ago

#143 new enhancement

Extended Designator Syntax for Arrays

Reported by: ajbeach Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description

I propose 3 new forms of designator in array initializer lists. The syntax reflects the syntax used in a case statement.

[0~9] = <expr>

Range initialization, initializes every index in the range.

['a', 'c'] = <expr>

List initialization, initializes every index in the list. Also every element of the list can be a single index or a range as above.

default = <expr>

Default initialization, initializes every index not initialized already. Maybe required to come last. This is the biggest break from the existing designator syntax but it is perhaps more well known from switch statements already.

Each form initializes several values, the expression should be evaluated only once and the result copied into place. That works for primitive types and types with trivial constructors. Interactions with constructors are left undefined for now.

One thing this does not cover is any new designator syntax for structures. There are three reasons for this. The first is constructors work better on structures so there is less need for it. Also this helps less since structures have mixed types. That means the list form is the most useful and the best syntax I have for fields is .x, y = <expr> which could use some work.

Change History (0)

Note: See TracTickets for help on using tickets.