Yay, that's exactly what our industry needs; more cargo cult programmers writing terrible software! Let's just be glad that this RoR guy isn't building anything safety critical.
120 karma · joined May 21, 2012
If you forget to include stdlib.h the cast hides the error and malloc will be assume to be a function which returns int. makes for interesting runtime errors.
Never cast the return value of malloc in C, and don't write redundant code. C is not C++.
array[2]
is the same as this: *(array + 2)
The compiler knows what the type of data the pointer refers to and can produce the byte offset itself. Also: "...it's always pointing at the first element of the the array"
Eh... an array can degrade into a pointer when needed, but what does the following produce? char arr[10];
??? x = &arr;
Is "x" a pointer to pointer to char? From your assessment it would seem so, but in reality the type of "x" is char (*)[10]
i.e., pointer to array of char 10. An array is an array, and arrays can degrade into pointer types.