Why am I getting this error:
infinite.c:5:12: error: use of undeclared identifier 'true'
while (true) {
1 error generated.
make: *** [infinite] Error 1
... when I try to compile this simple code for an infinite loop?
#include <stdio.h>
int main(void) {
int x = 0;
while (true) {
printf("%i\n", x);
}
}
The identifier is undeclaredIf the identifier is a variable or a function name, you must declare it before it can be used. A function declaration must also include the types of its parameters before the function can be used.
"Undeclared identifier" means that Delphi cannot find the declaration that tells it what showmassage is, so it highlights it as an item that hasn't been declared.
The identifier true
is not declared by default. To use it, two solutions :
<stdbool.h>
.However, the infinite loop for (;;)
is often considered as better style.
C has no built-in boolean types. So it doesn't know what true
is. You have to declare it on your own in this way:
#define TRUE 1
#define FALSE 0
[...]
while (TRUE) {
[...]
}
Include stdbool.h to use C99 booleans.
If you want to stick with C89 define it yourself:
typedef enum
{
true=1, false=0
}bool;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With