0
~/workspace/ $ make prototype
clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow    prototype.c  -lcrypt -lcs50 -lm -o prototype
prototype.c:6:1: error: expected identifier or '('
{
^
prototype.c:14:1: error: expected identifier or '('
{
^
2 errors generated.
make: *** [prototype] Error 1
~/workspace/ $ 

Please help me with what i am doing wrong. Looks like something silly but i cant figure what im doing wrong

1 Answer 1

1

Without the code, I can only guess, but maybe you confused function declarations and function definitions?

Function declaration:

bool is_positive(int);

or

bool is_positive(int num);

(variable names don't matter as they don't change the function signature)

This is required to use the function before you actually defined it. You usually find function declarations at the top of a .c file, or in a .h file.

Then there's also the function definition:

bool is_positive(int num)
{
    return num > 0;
}

Now consider faulty code

bool is_positive(int num);
{
    return num > 0;
}

The compiler would interpret the first line as a function declaration, and then not know how to treat the implementation, which does not seem to be related. The error message would be similar to yours.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .