If stack is empty, I tried to make an error, but I was warned.
Is there a cause?
if(isStackEmpty()){
error("stack is empty");
exit(1);
It contains speculation because only a part of the code is presented, but at least the error
function is not defined in the commonly used stdio.h, so if the purpose is to send a message in case of an error, shouldn't we use error
as the compiler warns us?
reference:
Standard C Library|Input/Output stdio.h|Wikipedia
(Excerpts only those with "error" in the name)
Sample code below (not required error()
pre-declared = bugged or old style)
#include<stdio.h>
# if 0
# include <stdlib.h>
void error(const char*message){
fprintf(stderr, "%s\n", message);
exit(0);
}
#endif
int main() {
error("stackoverflow");
}
Try to compile with cygwingcc-10.2.0
$gcc-c perrortest.c
perfortest.c:Infunction 'main':
errortest.c:10:2:warning:implicit declaration of function 'error'; did you mean 'error'? [-Wimplicit-function-declaration]
10 | error ("stackoverflow");
| ^~~~~
| error
$
Translating the warning freely
error
with a very similar name to the standard function error
is used without declaration, but is this a mistake in writing error
?If #if0
is set to #if1
, the error()
function is declared prototype before use and is used as declared, so there is no warning that the error
is incorrect.
So your source code is so fragmented that I can't say for sure, but if you add the original declaration of the error()
function, the warning will disappear.
© 2024 OneMinuteCode. All rights reserved.