Designated initializers for multi-dimensional arrays work great in C (C99), but fail in Objective-C (see example below). Given that Objective-C is proclaimed a strict superset of C, I consider this a bug. $ gcc -x c - <<<"int main(){ int a[3][4] = {[1][2] = 5}; }" $ gcc -x objective-c - <<<"int main(){ int a[3][4] = {[1][2] = 5}; }" <stdin>: In function 'main': <stdin>:1: error: syntax error before ']' token $
Subject: Re: New: Designated initializers for multi-dimensional arrays fail in Objective-C On Sun, 26 Jul 2009, sergei dot yakovlev at gmail dot com wrote: > Designated initializers for multi-dimensional arrays work great in C (C99), but > fail in Objective-C (see example below). Given that Objective-C is proclaimed a > strict superset of C, I consider this a bug. This was a property of the old C parser I carefully replicated when writing the new one. I do not know if there exists a C99-based specification of ObjC that clarifies what is intended (and note that this interacts with the old GNU form of designated initializers as well); I took it as given by the implementation at that time. /* ??? Following the old parser, [ objc-receiver objc-message-args ] is accepted as an initializer, being distinguished from a designator by what follows the first assignment expression inside the square brackets, but after a first array designator a subsequent square bracket is for Objective-C taken to start an expression, using the obsolete form of designated initializer without '=', rather than possibly being a second level of designation: in LALR terms, the '[' is shifted rather than reducing designator to designator-list. */
@fxcoudert: This is not an enhancement, this is a bug. Objective-C is declared as a strict superset of C. Everything that works in C should work in Objective-C. In this case, it doesn't, which means it's a bug.
Confirmed.
cc-ing objc maintainers