The idiom of returning the exact value of one of the arguments (of pointer type) exists in order to support "chained" function calls (also see strcpy
, strcat
etc). It allows you to write some repetitive code as a single expression statement instead of splitting it into multiple statements. For example
char buffer[1024];
printf("%s\n", strcat(strcat(strcpy(buffer, "Hello"), " "), "World"));
struct UserData data_copy;
some_function(memcpy(&data_copy, &original_data, sizeof original_data));
Even if you don't like this style of organizing code and prefer doing the same through multiple statements, the overhead of returning an [unnecessary] pointer value is virtually non-existent.
One can even say that the value of this idiom increased a bit after the introduction of compound literals in C99. With compound lterals this very idiom allows one to write the same code without introducing a named intermediate variable
printf("%s\n", strcat(strcat(strcpy((char [1024]) { 0 }, "Hello"), " "), "World!"));
some_function(memcpy(&(struct UserData) { 0 }, &original_data, sizeof original_data));
which makes sense since in most cases that named variable is supposed to be short-lived, is not needed afterwards, and only clutters the namespace.