Operating System - HP-UX
1755250 Members
5913 Online
108831 Solutions
New Discussion юеВ

error: expected an expression

 
rajeshmsr
Advisor

error: expected an expression

While migrating one of our app from Solaris to HP-UX, I am getting an error:

"./src/atk_db.pc", line 679: error #2029: expected an expression
STR_CAT_ALLOC(ps_query, ps_clause);
^

Note: The above code had been running fine on Sun OS 5.8.

The macro definitions are given below:

#define IS_NULL( x ) ((x) == NULL)
#define IS_EMPTY_STRING( x ) (IS_NULL( (x) ) || ((x)[0] == 0))
#define SAFE_STRING( s ) (!IS_NULL((s)) ? (s) : "")

#define P_FREE( x ) \
if ( (x) ) { \
P_free( (x) ); \
(x) = NULL; \
}

#define STR_COPY_ALLOC( d, s ) \
if ( (d) ) { \
P_FREE( (d) ); \
} \
(d) = P_newstr( P_string_va_length(SAFE_STRING((s)), NULL) + 1 ); \
P_string_copy( (d), P_string_va_length(SAFE_STRING((s)), NULL) + 1, SAFE_STRING((s)) );

#define STR_CAT_ALLOC( d, s ) \
if ( (d) ) { \
(d) = P_realloc( (d), P_string_va_length(SAFE_STRING((s)), SAFE_STRING((d)), NULL) + 1, char ); \
P_string_concat( (d), P_string_va_length(SAFE_STRING((s)), SAFE_STRING((d)), NULL) + 1, SAFE_STRING((s)) ); \
} else { \
STR_COPY_ALLOC( (d), (s) ); \
}

If anyone could shed light on this, it would be greatly helpful.
10 REPLIES 10
Steven Schweda
Honored Contributor

Re: error: expected an expression

> [...] from Solaris to HP-UX, [...]

Using which compilers?

If you could provide a small (but complete)
test case, then it would be easier to
investigate the right problem.

Most compilers (for UNIX) have a "-E" option
to let you see what the preprocessor puts
out. That might reveal something
interesting.
Dennis Handly
Acclaimed Contributor

Re: error: expected an expression

What version of aC++ are you using?

As Steven mentioned, you should inspect the .i file output by adding these options: -E -.i

Or you could do:
cc ... +legacy_cpp
This will use the off chip preprocessor before compiling and the compiler will point to the errors in the expanded source.
rajeshmsr
Advisor

Re: error: expected an expression

Thanks for the reply.

Now spotted the exact location of the error:(its pointing at the char keyword)

"./src/atk_db.pc", line 686: error #2029: expected an expression
(ps_query) = P_realloc( (ps_query), P_string_va_length((!((((ps_clause))) == 0L) ? ((ps_clause)) : ""), (!((((ps_query))) == 0L) ? ((ps_query)) : ""), 0L) + 1,char );
^
The char is passed to calculate the size to be allocated.

The macro definition is given below.

#define P_realloc(P, N, T) \
(T *)P_mem_manage((void *)(P), (N) * sizeof(T), P_MEM_MALLOCTRY, \
P_MEM_MALLOCDELAY, FALSE)

Please suggest a solution.
Dennis Handly
Acclaimed Contributor

Re: error: expected an expression

>Now spotted the exact location of the error: (it's pointing at the char keyword)

What did you change so that it is pointing to a new line?
What does the .i file show for that line?

>The macro definition is given below.

Is that macro defined before its use?
rajeshmsr
Advisor

Re: error: expected an expression

I didn't change the code. I generated the preprocessed file(.i file) by using the -E -.i option and then compiled the preprocessed file (i.e., the .i file). In that file, it is showing the error:
"./src/atk_db.pc", line 686: error #2029: expected an expression
(ps_query) = P_realloc( (ps_query), P_string_va_length((!((((ps_clause))) == 0L) ? ((ps_clause)) : ""), (!((((ps_query))) == 0L) ? ((ps_query)) : ""), 0L) + 1,char );
^

Note:The P_realloc is a macro. Even after preprocessing, this macro is not expanded. I have pasted the definition of the macro:

#define P_realloc(P, N, T) \
(T *)P_mem_manage((void *)(P), (N) * sizeof(T), P_MEM_MALLOCTRY, \
P_MEM_MALLOCDELAY, FALSE)
rajeshmsr
Advisor

Re: error: expected an expression

Edit: The macro is defined before it's use.
Dennis Handly
Acclaimed Contributor

Re: error: expected an expression

>The macro is defined before its use.

You need to use a bigger debugging hammer:
-E -.i +legacy_cpp -Wp,-C,-G

Then scan the .i file for P_realloc.
rajeshmsr
Advisor

Re: error: expected an expression

When I use the below options, it is throwing "too many arguments for the macro" at many places.
-E -.i +legacy_cpp -Wp,-C,-G

Temporary Fix: When I define the below macro in the source file itself, (instead of defining it in another file and including it here), the error is disappears.

#define P_realloc(P, N, T) (T *)P_mem_manage((void *)(P), (N) * sizeof(T), P_MEM_MALLOCTRY, P_MEM_MALLOCDELAY, FALSE)
Steven Schweda
Honored Contributor

Re: error: expected an expression

> Temporary Fix: When I define the below
> macro in the source file itself, (instead
> of defining it in another file and
> including it here), the error is
> disappears.

In my (limited) experience, C preprocessors
often care what they read, and in which
order, but they seldom care which file the
directives came from.

> If you could provide a small (but complete)
> test case, then it would be easier to
> investigate the right problem.

Still true.