4 ms·
depending upon how one has structured the code, a less painful way to write the same is: typedef char array[5]; void do_something(array *a) {
by dfawcus 10mo ago
depending upon how one has structured the code, a less painful way to write the same is:
typedef char array[5];
void do_something(array *a) {
enum { a_Size = sizeof *a };
memset(*a, 'x', a_Size);
}
it rather depends upon how painful it will be to create a bunch of typedefs.
Beyond a certain point, if there are too many arrays of the same size with different purposes, my inclination is to wrap the array in a struct, and pass that around (either by pointer or value depending upon circumstances.)
The existence of the decaying form is if I recall correctly a backward compatibility thing from either B or NB; simply because in one or the other pointers were written in the (current) array syntax form.
- int_19h 10mo agoIt stems from B, because it didn't have either pointers or arrays on the type level. Declaring an array allocated the storage, but the variable itself was still a word-typed pointer to said array. In fact, you could even reassign it! foo(a) { return(&a[1]); } bar() { auto a[10]; a = foo(a); } The decaying system made it mostly work with minimal changes in C.