I would like to understand the difference between passing *&p
and *p
and when to use one over another.
Say, I have a init function like the following.
void init(lua_State *L) {
L = luaL_newstate(); //allocate new memory to L
}
And in main()
if I try to access to L
, it crashes.
lua_State *L;
init(L);
do_something(L);//crash
However, when I change the argument type to lua_State *&L
, it no longer crashes.
Is it because allocating new memory changes value of pointer?
If so, isn't it better and safe to always pass with *&
instead of *
?
Is there any general rule about this?