简体   繁体   English

大型机上的C void指针

[英]C void Pointer on mainframe

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. 我尝试将mem强制转换为结构,但是我不确定sytnax,并且不断出错。 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. 我需要将其保留为空指针,因为稍后需要在函数中将其强制转换为char和int。

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. 您似乎期望找到一个从mem指向的地址开始的tcb结构,但是代码的目的是晦涩的,问题还不清楚。

If this is really the case, you can try this: 如果确实如此,则可以尝试以下操作:

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

You cannot dereference a void pointer. 您不能取消引用void指针。 You can think it this way if you have a void pointer, how will compiler know what type of address it is holding. 如果您有一个void指针,您可以这样想,编译器将如何知道它所持有的地址类型。 And by doing mem = mem->tcbtio how much offset it has to make. 并通过执行mem = mem->tcbtio来补偿多少。

Modify your function as: 将函数修改为:

void hexdump(void *mem, unsigned int len)
{
   struct tcbtio *mem2;
   mem2 = ((struct tcb*) mem) -> tcbtio;
   ...
   // Use mem2 later
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM