Strange array [1, 2] in C

Was there a very early C β€œstandard” where the following was legal for defining a two-dimensional array?

int array[const_x, const_y]; int array2[2, 10]; 

I stumbled upon old legacy code that uses this (and only that) notation for multidimensional arrays. The code, with the exception of this oddity, works great for C (and is surprisingly well-designed for the time).

Since I did not find macros that convert between [,] and [][] , and I assume this is not a form of practical joke, it seems that there was once your old C compiler that accepted this notation. Or am I missing something?

Edit: If this helps, this is for embedded microcontrollers (atmel). From experience, I can say that embedded compilers are not so well known for standard compliance.

The code on current compilers works as intended (as far as you can guess from the names of functions, descriptions, and variables) if I change everything [,] to [][] .

+7
source share
2 answers

The first formal standard was ANSI X3.159-1989, and the first unofficial standard would generally be considered the first edition of Kernigan and Ritchie. None of them allowed a comma to be used to declare a two-dimensional array.

This is apparently the idiosyncrasy of your particular compiler (the one that makes it non-standard, as it changes the semantics of some relevant programs).

+5
source

Take a look at this forum post .

the comma operator evaluates the left side, discards the result, then evaluates the right side. Thus, β€œ2.5” is the same as β€œ5”, and β€œ5.2” is the same as β€œ2”.

It may be what happens, although the reason for this is outside of me.

Note that the comma cannot be used when indexing a multidimensional array: the code A [i, j] evaluates to A [j] with the i dropped, and not the correct A [i] [j]. This differs from the syntax in Pascal, where A [i, j] is correct and can be a source of errors.

From Wikipedia

+5
source

All Articles