What will be the pNext pointer in the following case using C?

func()
{
    Object* pNext;
    func1(pNext);
}

func1(Object* pNext)
{
    pNext = Segement->GetFirstPara(0);
}

I expected this to be a pointer to firstpara returned from func1 (), but I see NULL, can someone explain and how to fix it to actually return a firstpara () pointer?

+3
source share
5 answers

For C ++ only, you can make a parameter a link

func()
{
    Object* pNext;
    func1(pNext);
}

func1(Object*& pNext)
{
    pNext = Segement->GetFirstPara(0);
}

. C . , (, Object ** Object * ). ++ ( &). , . , , ​​ .

+16

c :

func1(&pNext);
func1(Object** pNext) { *pNext = ... }

++

func1(pNext);
func1(Object*& pNext) { pNext = ... }

Object* func1, , . , pNext ( , ).

, , .

+5

, , .. Object** pNext. , . , , , .

func() { 
    Object* pNext;
    func1(&pNext);
}

func1(Object** pNext) { *pNext = Segement->GetFirstPara(0); }
+4

, pNext, . NULL, , 0x12AbD468 - . :

if( NULL != pNext )
{
  pNext->DoSomething();
}

... , , - , .

, "func1()" pNext , :

func()
{
  Object *pNext = func1();
}

Object* func1()
{
  return Segment->GetFirstPara(0);
}
+1
source

It should be


func()
{
  Object *pNext;
  func1(&pNext);
}

void func1(Object **pNext)
{
  *pNext = Segment->GetFirstPara(0);
}
0
source

Source: https://habr.com/ru/post/1698161/


All Articles