请教c中的setvect()以及getvect()用法! - CSDN论坛 - CSDN.NET

liuqian0422 2013-07-04 03:11:28
我在用c中的setvect()函数设置中断的时候老是出现"can not convert 'void (interrupt far *)()' to 'void interrupt far * )(...)'的错误,编译不过去。
...全文
314 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-07-04
  • 打赏
  • 举报
回复
outportb更不能在windows下使用。 在Windows下想操作端口,请参考WinIO.sys
赵4老师 2013-07-04
  • 打赏
  • 举报
回复
要想在Windows环境下稳定运行tc.exe 建一个批处理tc.bat,内容为下面两行,放在tc.exe同目录下,再将tc.bat发送到桌面快捷方式: del tc*.swp >NUL start command /c tc.exe 如果想在IDE里面使用鼠标,还应将快捷方式属性中的快速编辑模式关掉。 也可能在Windows下不能随便修改某些重要中断向量的值。 在DosBox下或纯DOS下试试。
liuqian0422 2013-07-04
  • 打赏
  • 举报
回复
程序在Turbo c++3.0下运行的,找了好多文章觉得不是程序的问题,是不是编译器的问题啊。代码是这样的: void interrupt far get_out(); /* interrupt prototype */ void interrupt (*far oldfunc)(); /* interrupt function pointer */ void main() { int i; for(i=0;i<500;i++) {error[i]=0;} disable(); oldfunc=getvect(0x1C); setvect(0x1C,get_out); enable(); } void interrupt get_out() { time_counter++; outportb(0x20,0x20); /*reset interrupt controller,8259,write '20H' to Port 20H*/ }
赵4老师 2013-07-04
  • 打赏
  • 举报
回复
要想在Windows环境下稳定运行bc.exe 建一个批处理bc.bat,内容为下面两行,放在bc.exe同目录下,再将bc.bat发送到桌面快捷方式: del tc*.swp >NUL start command /c bc.exe 如果想在IDE里面使用鼠标,还应将快捷方式属性中的快速编辑模式关掉。 bc++3.1 帮助里面对每个函数都有一小段能拷贝出来运行看效果的例子程序。非常适合初学C语言。相比较而言VC带的帮助MSDN就没有。http://download.csdn.net/source/2805028 BC++3.1帮助中自带的例子:
/***NOTE:
    This is an interrupt service routine.  You can NOT compile this
    program with Test Stack Overflow turned on and get an executable
    file which will operate correctly. */

#include <stdio.h>
#include <dos.h>
#include <conio.h>

#define INTR 0X1C    /* The clock tick interrupt */

#ifdef __cplusplus
    #define __CPPARGS ...
#else
    #define __CPPARGS
#endif

void interrupt ( *oldhandler)(__CPPARGS);

int count=0;

void interrupt handler(__CPPARGS)
{
/* increase the global counter */
   count++;

/* call the old routine */
   oldhandler();
}

int main(void)
{
/* save the old interrupt vector */
   oldhandler = getvect(INTR);

/* install the new interrupt handler */
   setvect(INTR, handler);

/* loop until the counter exceeds 20 */
   while (count < 20)
      printf("count is %d\n",count);

/* reset the old interrupt handler */
   setvect(INTR, oldhandler);

   return 0;
}

70,031

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧