Re: [cc65] malloc and Sort.c(26): Error: Expression expected

Date view Thread view Subject view

From: Marko Mäkelä (
Date: 2003-03-04 08:07:28

On Mon, Mar 03, 2003 at 10:46:20PM -0800, Greg Long wrote:
> Is there an unusual syntax for malloc?  I notice it doesn't like to take
> anything but a constant.

It's a good idea to produce a minimal input file that triggers the error.
In this case, I'd suspect two other errors in your code:

> 	unsigned int* ra; //declare array
> 	ra = (unsigned int*) malloc(sizeof(unsigned int[size] ));
> 	unsigned int i = size;//line 20

The string "//" might not be a comment delimiter in the dialect of C
that cc65 supports.  Use /* */ comments instead.

Also, you can't declare variables except in the beginning of a block.
Swap the lines starting with "ra" and "unsigned int i", and it should
work.  I'd rather write the four above lines like this:

unsigned int i = size;
unsigned int* ra = malloc (size * sizeof *ra);

Disclaimer: I haven't used cc65 yet, only other C compilers.

To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.

Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-03-04 08:10:07 CET