Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I hope this is the right forum for this ... Well, in C, the standard library uses usually (void* buffer, int size) when referring to some data buffer. I wonder if there is a rationale for this order instead of (int size, void* buffer). I couldn't think of any good reason, and it seems to be an arbitrary choice, but I'm curious to here if there is some deeper meaning behind this order.

share|improve this question
    
alphabetical order, obviously. b uffer comes before s ize. Or something else. –  littleadv Nov 8 '11 at 20:51
6  
Totally arbitrary. Just be consistent. –  ChrisF Nov 8 '11 at 20:54
1  
Well, something like process (3, elements) is closer to plain English, which makes it more "natural". –  Anteru Nov 8 '11 at 21:35
add comment

2 Answers

In C you can't do object->method(value), so it's idiomatic to put the "object"—the thing whose state you're changing—as the first parameter, and prefix the function name with the "class." The C standard library makes a lot more sense when you think about it that way. For example, strcpy(dest, src) reads as dest->cpy(src), where dest is a str object.

share|improve this answer
add comment

Generally you prefer the data parameters first and then the const values. There is also a preference for the result first eg strcpy(dest,src) memcpy(dest,src)

In c++ it's useful because you can have default parameters at the end.

share|improve this answer
    
Yeah, which I/most people I know always wind up doing wrong, because you say "I want to copy a to b" (usually) but you write it the other way round. –  Anteru Nov 8 '11 at 21:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.