显式转换为转换 [英] Explicit cast to convert

查看:70
本文介绍了显式转换为转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在编写程序,这将允许我手动读取软盘上的扇区并且有点麻烦。该程序旨在运行在DOS32 / 16环境中,所以我使用数字mars c编译器编译c和一些内联汇编语言与参数''dmc filename -msd'',但我有编译器给我的问题错误:在尝试为指针提供内存位置时,显式强制转换将参数1从int *转换为int。我认为问题可能在于编译器限制这些操作,因为它们可能被认为是危险的,但需要直接引用内存。任何人都可以给我任何建议吗?


让我烦恼的代码部分是:


int * memsectptr

memsectptr =(int *)0x1000;

for(i = 0; i<(sectorize); i ++)

{

fputc( *(memsectptr + i),outfileprev); / *使用前获取内存值* /

}


谢谢,

Dinklebaga

Hi All,
I am writing a program at the moment that will allow me to manually read sectors on a floppy disk and have come into a bit of bother. The program is designed to run in a DOS32/16 environment so I am using the digital mars c compiler compiling c and some inline assembly language with the parameters ''dmc filename -msd'', but i am having issues with the compiler giving me the error: explicit cast to convert parameter 1 from int* to int when trying to give a memory location to a pointer. I believe the problem may lie with the compiler restricting these operations because they may be considered dangerous but they are needed to directly reference the memory. Can anybody offer me any advice?

The section of code giving me bother is:

int *memsectptr
memsectptr = (int *)0x1000;
for(i=0; i<(sectorsize); i++)
{
fputc(*(memsectptr+i), outfileprev); /*get memory values before use*/
}

Thanks,
Dinklebaga

推荐答案

变量的类型是什么?i?

具体哪条线在您的错误消息中显示?

您是否正在获取编译器错误或编译器警告

*(memsectptr + i)使用指针算术样式。假设i,这看起来很好。是一个int。


它没有解决你的问题,但根据你的程序的其余部分你可能更喜欢这个声明:
What is the type of variable "i"?
Specifically which line is indicated in your error message?
Are you getting a compiler error or a compiler warning?

*(memsectptr+i) uses pointer arithmetic style. This looks ok assuming "i" is an int.

It doesn''t solve your problem, but depending on the rest of your program you might prefer this declaration:
展开 < span class =codeDivider> | 选择 | Wrap | Line数字


你好Donbock,

首先谢谢你回复。是的,我被设置为一个整数,只是为了保持sectorize(512,2048等)的值,但我得到的是编译器错误,这使我无法编译程序。我发布的代码部分实际上只是整个程序的一小部分,但是这部分让我感到悲伤。就像你观察到的那样,我确实希望将指针的值设置为0x1000但我想要访问存储在指针处的数据(从指针开始的512个字节)。通常我会使用malloc但因为程序部分在asm中我需要直接引用内存位置。


谢谢,

Dinklebaga
Hi Donbock,
Firstly thankyou for replying. Yes i is set as an integer just simply to hold the value of the sectorsize (512, 2048, etc.) but what i am getting is compiler errors which stop me from compiling the program. The section of code that i have posted is actually only a small section of the entire program but it is this section which is causing me grief. Like you have observed I do want to have the value of the pointer set to 0x1000 but I then want to access the data that is stored at the pointer (the 512 bytes that start at the pointer). Usually i would use malloc but because the program is partly in asm I need to reference the memory location directly.

Thanks,
Dinklebaga


错误消息是否涉及特定的行号?如果是这样,它是哪一行?


我假设错误是你为memsectptr分配0x1000的行或你调用fputc的行。


如果错误是对fputc的调用,你可以尝试声明一个新的int *变量,将memsectpr + i分配给那个新变量,然后将该变量传递给fputc。
Does the error message refer to a specific line number? If so, which line is it?

I assume that the error is either for the line where you assign 0x1000 to memsectptr or to the line where you call fputc.

If the error is for the call to fputc you might try declaring a new int* variable, assigning memsectpr+i to that new variable, and then passing that variable to fputc.


这篇关于显式转换为转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆