I was doing some C coding and after reading some C code I’ve noticed that there are code snippets like
char *foo = (char *)malloc(sizeof(char) * someDynamicAmount);
So I want to ask what’s more C-ish way to allocate memory for char array? Use sizeof(char) and supposedly future-proof the code against any standard changes or omit it and use the number directly?
The more Cish way would be
referencing the variable and not the type so that the type isn’t needed.
And without casting the result of malloc (which is C++ish).