Answering a question about order of parameters it struck me that strcpy (and family) are the wrong way round. Copy should be src -> destination.
Is there a historical or architectural reason for the dest,src order in these 'C' functions? Something to do with optimization of the stack on the PDP-8 or something?
3 Answers 3
Think of it like an assignment operation.
A = B; //copies the contents of B into A
Same order when using memcpy to copy an array.
memcpy(A, B, sizeof(B)); //copies the contents of B into A
Putting the target as the second argument would be inconsistent with other functions that write things to strings and have the target in the first argument. memset(3)
and sprintf(3)
come to mind.
I don't think anyone will know for certain the true answer, although many will speculate why, and now we can no longer ask Dennis Ritchie, the definitive answer is probably not possible. (Can anyone provide an evidence based answer?)
However, I do belive you assertion that the order is "wrong" is wrong. It is what it is. On the right in the UK: there is no right or wrong, it's just because it's that way - as long as everyone does it the same way around.
-
There are logical reasons for driving on the left, and historical/political ones for switching to the right, but it's a bit OT for programmers.soMartin Beckett– Martin Beckett2012年07月14日 14:08:34 +00:00Commented Jul 14, 2012 at 14:08
mov eax, 0xffffffffh;
is your answer.movl 0xffffffff, %eax
. I don't get your point.