When would you pass by reference instead of a pointer?

when would you pass by reference instead of a pointer?

Pointer
inline uint64_t FIFO::UpdateIndex(uint64_t* const indexPtr)
{
uint64_t current = *indexPtr;

*indexPtr = *indexPtr < BUFFER_SIZE - 1 ? *indexPtr + 1 : 0;

return current;
}

vs

Reference
inline uint64_t FIFO::UpdateIndex(uint64_t& const index)
{
uint64_t current = index;

index = index < BUFFER_SIZE - 1 ? index + 1 : 0;

return current;
}

Attached: fxhg.png (539x539, 323K)

Other urls found in this thread:

en.wikipedia.org/wiki/Persistent_data_structure
twitter.com/NSFWRedditImage

Imagine actually being a sepplescuck.

I'd love to try to help you but I don't know how to code in any language

you dont ever pass by pointer.
Encapsulate resources in objects & use references + move semantics to pass stuff around instead.

whenever the ptr is supposed to be non-null and point to existing lvalue object

i don't see a difference if they're both const

>ramming posts
>kill em all

That makes sense…
Thanks

uint64_t* const indexPtr
and
const uint64_t* indexPtr

mean different things

>ptr is supposed to be non-null and point to existing lvalue object
void f(uint64_t* in[static 1]);

en.wikipedia.org/wiki/Persistent_data_structure

don't use raw pointers ever unless required by some niggerlicious library your niggerlicious job demands you use

Pointers are faster imagine asking for way to next toilet would u rather have someone pointing at the toilet or some vague poo references?

reference are deprecated in C++20 for a good reason. STL never could make proper use of them look at std::reference_wrapper::
std::vector
std::vector

Red Pilled and based

Reference is example is bad, a reference is inherently const because you can rebind. What you probably wanted was a const value, but you put the const in the wrong place for both examples.

Can’t rebind.

two reasons they exist
T& operator(size_t i)[];
and C++ grammer is to hard.
const int*** const is a valid type

god i hate c++

one day some C++ faggot said i can improve unions with type safety. He/She added a type flag to the union and invented std::visit! instead off using overloaded function.

> T& const

Attached: wut.jpg (200x200, 7K)

sorry, my bad I didn't even compile it, I just typed it in for the post

Imagine being this much of a faggot.
Write in C, nigger.

who cares just let the compiler inline everything lmao

...

>reference are deprecated in C++20
[Citation, Nigger]

there is no reason to use raw pointers in any modern language

chill chill im just learning right now