Domanda

I'm currently working on modifying a dump program, but I can't figure out how to properly navigate with a void pointer. Below is the function that I'm working in, and the instruction that I'm trying to execute. I've tried casting mem to a struct, but I'm not sure of the sytnax and I keep getting an error. For the code below, the specific error I'm getting is:

       47       |   mem = mem->tcbtio                                    
===========> .........a..............................................
*=ERROR===========> a - CCN3122 Expecting pointer to struct or union.

Here is my function:

void hexdump(void *mem, unsigned int len)
{                                        
   mem = mem->tcbtio;                     
   ...
}  

Here are my struct defintions:

struct psa {           
 char psastuff[540];   
 struct tcb *psatold;  
        char filler[4];
 struct ascb *psaaold; 

};                     

struct tcb {           
 struct prb *tcbrb;    
 char tcbstuff[8];     
 struct tiot *tcbtio;  
};           

struct tiot {     
 char tiocnjob[8];
 char tiocpstn[8];
 char tiocjstn[8];
};

I need to keep it as a void pointer, as I need to cast it to char and int later on in the function.

È stato utile?

Soluzione

It seems as you are expecting to find a tcb struct, starting at the address pointed by mem, but the aim of the code is obscure and the question not clear.

If this is really the case, you can try this:

   mem = ((struct tcb *)mem)->tcbtio;                     

Altri suggerimenti

You cannot dereference a void pointer. You can think it this way if you have a void pointer, how will compiler know what type of address it is holding. And by doing mem = mem->tcbtio how much offset it has to make.

Modify your function as:

void hexdump(void *mem, unsigned int len)
{
   struct tcbtio *mem2;
   mem2 = ((struct tcb*) mem) -> tcbtio;
   ...
   // Use mem2 later
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top