0

I have following piece of code where I am getting an error of

error: expected expression before const (at line 15)

 12 : int
 13 : function1(const char *arg1, const char **arg2)
 14 : {
 15 :        int i = function2(const char *arg1, const char **arg2);
 16 : }

 18 : int
 20 : function2(const char *arg1, const char **arg2)
 21 : {
 22 : }

what does that exactly mean?

Thanks

1
  • 1
    int i = function2(arg1,arg2); Commented Apr 6, 2014 at 4:16

6 Answers 6

2

Remove int i = function2(const char *arg1, const char **arg2); With int i = function2(arg1,arg2);

Your variables are already defined. when calling to function in C you shouldn't say parameters type , you have to pass parameters themselves.

Sign up to request clarification or add additional context in comments.

Comments

2

Line 15 is a mistake. In C, variables are identified by a single token called an identifier.

In this case, the names of the variables are arg1 and arg2. You use those tokens when you are using the variables; you don't repeat all of the type information associated with the variable.

So the line should be:

int i = function2(arg1, arg2);

Comments

2

You already have arg1 and arg2 being passed in to your function1, so you just need

int i = function2(arg1, arg2);

Comments

2
int i = function2(const char *arg1, const char **arg2);

You are trying to call function2, but you have written the call like a function declaration. You don't specify the argument types when calling the function.

Comments

1

Remove the * and try? It seems like you're trying to pass arg1 and arg2 into function 2, but I don't think they can be referenced that way inside the function, because they weren't defined there. I believe it should be just function2(arg1,arg2)

Comments

1
error: expected expression before const (at line 15)

Q What does that exactly mean?

A It means that the first thing after function2( is expected to be an expression. const is not an expression. arg1 will be an expression.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.