-2

I am a computer science student and recently learned how to use interrupts in C. after a couple of search in web I came up with this code:

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

#ifdef __cplusplus

    #define __CPPARGS ...

#else

    #define __CPPARGS

#endif

#define INTR 0x1c
#define gotoxy(x,y) printf("\033[%d;%dH", (x), (y))
//#define clear() printf("\033[H\033[J");
/*
//positioning
void gotoxy(int x, int y)
{
    printf("%c[%d;%df",0x1B,y,x);
}
*/

void interrupt handler(__CPPARGS);
void interrupt ( *oldhandler)(__CPPARGS);

int countS = 0;
int s = 0;
int m = 0;
int ms = 0;
int l = 0;
int flag = 0;

int main(void)
{
    clrscr();
    printf("%02d:%02d:%02d",m,s,ms);
    oldhandler = getvect(INTR);

    setvect(INTR, handler);
    char c;

    while(1)
    {
        c = getch();

        switch(c){

            case 'e':
                goto exit_loop;
                break;

            case ' ':
                flag = 1-flag;
                break;

            case 'r':
                flag = s = m = ms = l = 0;
                clrscr();
                printf("%02d:%02d:%02d",m,s,ms);
                break;

            case 'l':
                gotoxy(++l,0);
                printf("%02d:%02d:%02d",m,s,ms);
                break;
        }
    }

    exit_loop:;
    setvect(INTR, oldhandler);
    return 0;
}

void interrupt handler(__CPPARGS)
{

    if(flag == 1){

        countS++;
        ms += 55;

        if(countS == 18)
        {
            countS = ms = 0;
            s++;

            if(s==60)
            {
                m++;
                s = 0;
            }
        }

        gotoxy(0,0);
        printf("%02d:%02d:%02d",m,s,ms);
    }
}

this code is some kind of stopwatch in C console application and its work perfect in historical Turbo C++. I changed my IDE and now using Visual studio 2013, when i create a new project in Visual C++->win32ConsoleApplication and paste this code in the main file. its not work. then an error says that i should add #include "stdafx.h" in the first of my file. after doing so, this is my main error list:

Error   1   error C2146: syntax error : missing ';' before identifier 'handler' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32  1   ConsoleApplication1
Error   2   error C2182: 'interrupt' : illegal use of type 'void'   c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32  1   ConsoleApplication1
Error   3   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 32  1   ConsoleApplication1
Error   4   error C2065: 'oldhandler' : undeclared identifier   c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   5   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   6   error C2086: 'int interrupt' : redefinition c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   7   error C2143: syntax error : missing ';' before '('  c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   8   error C2059: syntax error : ')' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   9   error C2059: syntax error : ';' c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 33  1   ConsoleApplication1
Error   10  error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 44  1   ConsoleApplication1
Error   11  error C2065: 'oldhandler' : undeclared identifier   c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46  1   ConsoleApplication1
Error   12  error C3861: 'getvect': identifier not found    c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 46  1   ConsoleApplication1
Error   13  error C3861: 'setvect': identifier not found    c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 48  1   ConsoleApplication1
Error   14  error C3861: 'clrscr': identifier not found c:\users\mohammad\documents\visual studio 2013\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp 67  1   ConsoleApplication1

these errors are related to these lines:

void interrupt handler(__CPPARGS);
void interrupt ( *oldhandler)(__CPPARGS);

and using of: clrscr();

my operation system is windows 10-64bit and its my first time programming in c/c++ in visual studio. I do some in Turbo c++ and devC++ before but only Turbo c++ run this sample and not even devC++. what is the diffrenses and how should I solve this? thanks

  • 1
    MS-DOS is dead. – Weather Vane Nov 27 '16 at 17:43
  • 2
    MS-DOS remains dead. And we have killed it. How shall we comfort ourselves, the murderers of all murderers? What was holiest and mightiest of all that the world has yet owned has bled to death under our knives: who will wipe this blood off us? – Cody Gray - on strike Nov 27 '16 at 17:55
  • MS-DOS was dead: to begin with. There is no doubt whatever about that. The register of its burial was signed by the clergyman, the clerk, the undertaker, and the chief mourner. Windows signed it. And Windows's name was good upon 'Change, for anything it chose to put its hand to. – user4581301 Nov 27 '16 at 18:15
  • 1
    It's also worth noting that Turbo C++ is a couple decades old and predates the standardization of C++. It may as well be considered a different language at this point. – user4581301 Nov 27 '16 at 18:18
  • 1
    The slow death began when MS inverted the MS-DOS/Windows hierarchy after it became plain that road was a dead-end. Instead of trying to run Windows on MS-DOS, they made MS-DOS run on Windows. We can assuage our guilt by building shrines within our systems, so that we may pay homage to MS-DOS and run ancient code and even create new code with its venerated compilers, although you will not find me there. – Weather Vane Nov 27 '16 at 18:23
  • I miss pointers, both near and far. Not. – doug Jul 30 '21 at 04:14

1 Answers1

0

You are working in 64-bit long mode, so you don't have access to real-mode BIOS interrupts or MS-DOS services. Your code has a number of other issues but the bottom line is it's not going to work without a 16-bit compiler and an emulator (like the NTVDM which is absent on 64-bit Windows)

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
  • so you mean i cant fix this in visual studio or should i install some other plugins or compiler in it? what should i do now? is there any modern ide that can do as turbo c++ without any problem? – mohammad fallah.rasoulnejad Nov 28 '16 at 05:43
  • @mohammadfallah.rasoulnejad You need to install an 8086 emulator like DOSBox or emu8086 and write your code on a compiler within that - 16-bit real mode cannot be emulated in a 64-bit OS. See http://wiki.osdev.org/Real_Mode – Govind Parmar Nov 28 '16 at 15:19