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

Date view Thread view Subject view

From: Greg Long (greg_at_maneuveringspeed.com)
Date: 2003-03-04 07:46:20


Is there an unusual syntax for malloc?  I notice it doesn't like to take
anything but a constant.

The real curious thing is how it generates an error on the line of code
FOLLOWING the use of malloc. In my example below line 20 is fine

I'm used to ANSI and MS C++, but not C - which I'm brand new to. I
wouldn't imagine there are any C++ compilers for the 6502?

Having said these gripes...it looks like a wonderful compiler vs. the
alternative of coding in Assembly...if I can just get anything to
compile!

My code which has the trouble:

#include <stdlib.h>
#include <time.h>
#include <conio.h>

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

	//generate random numbers
	while(i)
	{
		ra[i] = rand();
		--i;
	}
	return 0;
}


/*	The errors:
ShellSort.c(18): Error: Constant expression expected
ShellSort.c(20): Error: Expression expected
ShellSort.c(20): Error: `;' expected
ShellSort.c(20): Error: Expression expected
ShellSort.c(20): Error: `;' expected
ShellSort.c(20): Error: Expression expected
ShellSort.c(20): Error: `;' expected
ShellSort.c(20): Error: Expression expected
ShellSort.c(20): Error: `;' expected
ShellSort.c(20): Error: Expression expected
ShellSort.c(20): Error: `;' expected
ShellSort.c(20): Fatal: Too many errors
*/


----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de 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 07:48:18 CET