I am trying to print a string using DOS video memory but when I call function print_Id ();
and (*old)();
it shows these warnings and does not run the code but without these functions every thing works fine.
Call to function print_id
with no prototype
Call to function with no prototype
I wrote this function at the top but all in vain.
Please review my code below; I am using BORLANDC compiler.
#include<stdio.h>
#include<BIOS.H>
#include<DOS.H>
#include<conio.h>
int j;
void interrupt (*old)();
void interrupt print_name();
void interrupt print_Id();
char st[80] ={"Bilal Maqsood$"};
char id[20]={"BC110403231$"};
char far *scr=(char far* ) 0xb8000f3C;
int main( )
{
clrscr();
old=getvect(0x08);
setvect(0x08,print_name); //corrected
return 0;
}
void interrupt print_name(){
int i=0;
int j=0;
while(st[i]!='$'){
*(scr+j)=st[i];
*(scr+j+1)=0x72;
i++;
j+=2;
}
print_Id ();
}
void interrupt print_Id ( )
{
int i=0;
int j=0;
while(id[i]!='$'){
*(scr+j)=id[i];
*(scr+j+1)=0x17;
i++;
j+=2;
}
(*old)();
}
You should be getting a compiler warning for the three declarations:
void interrupt (*old)();
void interrupt print_name();
void interrupt print_Id();
These declare one function pointer and two functions. None of these defines a prototype in C. The latter two declare the existence of a function and that the return types are void
(and interrupt
is a Borland-specific or DOS-specific noise word). But the empty parentheses mean "the argument list is undefined, except that it is not a variadic function — so there is no ...
ellipsis in the actual argument list".
To make them into prototypes, you need to specify explicitly that the functions take no arguments:
void interrupt (*old)(void);
void interrupt print_name(void);
void interrupt print_Id(void);
This is different from C++, where the empty parentheses mean 'no arguments'. The difference was necessary when C was standardized because prototypes had not been a part of C before the C89/C90 standard, and all existing code had to use the empty parentheses to mean "the function exists but you don't know anything about the function arguments" and the standard would have failed had it broken all the existing C code.
The reason you are only getting the warning for the two calls is precisely because the warning is generated when the function name or function pointer is used to call the function; not when the function name is used as a function pointer. All three need to be fixed.
Incidentally, I prefer to have the declarations and definitions consistent, so I always use the explicit void
argument list in the function definition too; it ensures that the function definition provides a prototype if it stands alone, too.