This question came about as a result of some mixed-language programming. I had a Fortran routine I wanted to call from C++ code. Fortran passes all its parameters by referen
C++ doesn't define how implementations should be, it's just a language. So there isn't "a" implementation of references.
That said, references are implemented with pointers. This leads to a lot of confusion ("references are just pointers", "references are just pointers with the mundane parts taken out") but that is not the case. References are aliases and will always be aliases.
The compiler will pass the address of a variable, and operate with that pointer. This has the same effect (but not the same semantics!). To be more concrete, a compiler might "replace" this:
void make_five(int& i)
{
i = 5;
}
int main(void)
{
int i = 0;
make_five(i);
}
With this:
void make_five(int* const i)
{
*i = 5;
}
int main(void)
{
int i = 0;
make_five(&i);
}
(In practice such a simple function would be inlined, but you get the point.) Hence why your colleague suggested you use a pointer.
Keep in mind references are to be preferred. This is where the distinction between references and pointers is important. Do you want to alias a variable, or do you want to point at it? Most of the times, the former. In C, you had to use a pointer to do this, and this contributes to the common C-programmer misconception that references are actually pointers.
To get similar semantics (since you are now pointing to a variable, and not aliasing it), you should ensure the value of the pointer is not null:
extern "C" void FORTRAN_ROUTINE (unsigned * flag)
{
assert(flag); // this is normally not a problem with references,
// since the address of a variable cannot be null.
// continue...
}
Just to be safe.