Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

Tags:

c

gcc

token

I get this error in a C header file in this line :

char * getFechaHora(time_t & tiempoPuro);

In a C source code file i am including the header file and giving the function an implementation

char * getFechaHora(time_t &tiempoPuro){...}

also in my header file i am including correctly the "time.h" library.

like image 465
Youssef Khloufi Avatar asked Oct 15 '12 21:10

Youssef Khloufi


People also ask

What does error Expected mean?

expected” This error occurs when something is missing from the code. Often this is created by a missing semicolon or closing parenthesis.

How do you fix error expected before token?

Error: expected ')' before ';' token in C Consider the given example, here I terminated the #define statement by the semicolon, which should not be terminated. How to fix? To fix this error, check the statement which should not be terminated and remove semicolons.

What is error expected ')' before '(' token?

The " expected identifier before '(' token " error occurs because you are using -> operator to access a field of a struct and, instead of passing the field identifier, you are passing a '(' character. Here is the list of errors. av->(A. code) is bad syntax.

What does error Expected mean in C?

It means the syntax is invalid.


3 Answers

char * getFechaHora(time_t & tiempoPuro);

This is not C. C has no reference (&).

like image 198
ouah Avatar answered Oct 18 '22 16:10

ouah


In C, if char * getFechaHora, this is your function and the two (time_t & tiempoPuro) are arguments you should declare the function as:

char * getFechaHora(*type* time_t, *type* tiempoPuro);

else if the second is a variable, declare as

char * getFechaHora(time_t *tiempoPuro);
like image 35
Optimus Prime Avatar answered Oct 18 '22 15:10

Optimus Prime


The problem is your use of the & symbol. Passing by reference in that way is not supported in C. To accomplish this in C, you need to pass in a pointer to the variable like so:

    char * getFechaHora(time_t * tiempoPuro);

Technically, you are still passing by value (passing the value of the pointer), but it will accomplish the same thing (modifying the value pointed to by the tiempoPuro variable local to the getFechaHora function will change the value of the variable local to the function it was called from).

Reference: Pass by Reference

like image 26
Daniel Hopkins Avatar answered Oct 18 '22 16:10

Daniel Hopkins