Guidance on using pointers vs. references for function arguments


Carrying on this conversation from llvm-commits:

Would it be reasonable if we name both SwapByteOrder() -- it's


to describe their purpose in any other way -- and make the in-place
function take a pointer, instead of a reference?

Pointer is the wrong API: it implies having to check for null.

I see that in general, the choice between pointer parameters and


parameters can mean one of many things: input vs output, change of


vs no change, validity of NULL, and perhaps more.

For example, Google C++ Style Guide mandates: "All parameters passed by
reference must be labeled const. [...] it is a very strong convention in
Google code that input arguments are values or const references while


arguments are pointers."


cppguide.xml#Reference_Arguments )

I haven't seen much of that around here.

I see that LLVM Coding Standards document doesn't touch this subject at


Should we use this opportunity to add to it that in LLVM, the choice


pointer parameters and reference parameters is defined by whether NULL is


valid input?

Not sure that's necessary, but feel free to send a proposal to llvmdev.

What does the community think about such an addition?