3 ms·
Again the lack of a built in array type with both data+length shows. Leaving this out of C must be the most expensive mistake in progranning history, after null
by Too 9y ago
Again the lack of a built in array type with both data+length shows. Leaving this out of C must be the most expensive mistake in progranning history, after null. Imagine all the security holes stemming from that and now also it shows that it is preventing optimizers. At least now it's finally available with cppcoreguidelines.
- CodeArtisan 9y agohttps://port70.net/~nsz/c/c11/n1570.html#6.7.6.3p7 https://port70.net/~nsz/c/c11/n1570.html#6.7.6.3p7 "A declaration of a parameter as ''array of type'' shall be adjusted to ''qualified pointer to type'', where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation. If the keyword static also appears within the [ and ] of the array type derivation, then for each call to the function, the value of the corresponding actual argument shall provide access to the first element of an array with at least as many elements as specified by the size expression." According to this, the following syntax could be used for optimization void foo(size_t n, int array[static n]) {...} pointers to array could be used too void foo(size_t n, int (*array)[n]) { printf("array %zu, *array %zu\n", sizeof(array), sizeof(*array)); } foo( 10, null); // array 8, *array 40 foo(100, null); // array 8, *array 400