Re:Everything I wish I knew when learning C
by Joker_vD on Tuesday November 29, 2022 @06:12AM
(#33786100)
Another one corner of the language where arrays actually being arrays is important is multidimensional array access:
This works because (arr + 3) has type "pointer to int[7]", not "pointer to int". The resulting address computation is
That's also another reason why types like "int [5][7][]" are legal but "int [5][][]" are not.
[ Parent
| on HN ]
Re:Everything I wish I knew when learning C
by ErikCorry on Tuesday November 29, 2022 @06:51AM
(#33786394)
Really, are multidimensional arrays an important part of the language?
The above code looks like it's indexing into an array of pointers. If you want a flat array, make a few inlined helper functions that do the multiplying and adding. Your code will be much cleaner and easier to understand.
Re:Everything I wish I knew when learning C
by Joker_vD on Tuesday November 29, 2022 @09:02AM
(#33787661)
Of course multidimensional arrays are an important part of the language, just as the ability to have structs inside structs.
> The above code looks like it's indexing into an array of pointers. If you want a flat array, make a few inlined helper functions that do the multiplying and adding. Your code will be much cleaner and easier to understand.
It is a "flat" array already, not an array of pointers: [0]. No need to write the code that compiler generates for you already.
Re:Everything I wish I knew when learning C
by ErikCorry on Tuesday November 29, 2022 @09:39AM
(#33788129)
I am aware that it's flat already.