PDA

View Full Version : تشریح کد درون help کامپایلر



suraty
جمعه 27 خرداد 1390, 16:58 عصر
با سلام
این کدی است که در help کامپایلر برای تابع setvect آورده شده. من هر چه تلاش کردم از آن سر در نیاوردم. به خصوص که در حین اجرا داخل حلقه while افتاده و از آن خارج نمی شود. خواهش می کنم اگر می توانید در فهمیدن این کد راهنماییم نمایید. به ویژه قسمت اولش که یک if را به صورت دستور پیش پردازنده معرفی کرده است.


/* getvect and setvect example */

/* * * * * * * * * * * * * * *
NOTE: This is an interrupt service routine.
You can NOT compile this program with
Test Stack Overflow turned on and get an
executable file that 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;
}