symbol '_heap' not defined

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
cborn
Well known member
Posts: 280
Joined: Tue Oct 06, 2020 7:45 pm

symbol '_heap' not defined

Post by cborn »

Hello
the (downpage) example for an 1-d array from
https://overiq.com/c-programming-101/ch ... nter-in-c/

Code: Select all

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n, i;
    char *ptr;
    printf("Enter number of characters to store: ");
    scanf("%d", &n);
    ptr = (char*)malloc(n*sizeof(char));
    for(i=0; i < n; i++)
    {
        printf("Enter ptr[%d]: ", i);
        /* notice the space preceding %c is
          necessary to read all whitespace in the input buffer        */
        scanf(" %c", ptr+i); 
    }
    printf("\nPrinting elements of 1-D array: \n\n");
    for(i = 0; i < n; i++)
    {
        printf("%c ", ptr[i]);
    }
    // signal to operating system program ran fine
    return 0;
}
works ok with gcc , saved as malloc_test.c.
but with zcc i get

Code: Select all

~/Desktop/try-C/c_in_zx$ zcc +zx -vn malloc_test.c -o malloc_test -lndos -create-app
Error at file 'malloc.asm' line 16: symbol '_heap' not defined
Errors in source file /home/chris/z88dk/lib/config/../..//lib/target/zx/classic/spec_crt0.asm:
Error at file 'malloc.asm' line 16: symbol '_heap' not defined
what do i need? i included some 'standard' extra
#include <spectrum.h>
#include <stdio.h>
#include <stdlib.h>
#include <input.h>
#include <string.h>


this thread mentions 'long heap'
https://www.z88dk.org/forum/viewtopic.p ... 958#p17958
User avatar
dom
Well known member
Posts: 2090
Joined: Sun Jul 15, 2007 10:01 pm

Re: symbol '_heap' not defined

Post by dom »

The heap needs configuring, it's easiest to go with AMALLOC which auto configures the heap: https://github.com/z88dk/z88dk/wiki/Cla ... figuration

Basically, add -DAMALLOC or -pragma-output:USING_amalloc to the command line.
cborn
Well known member
Posts: 280
Joined: Tue Oct 06, 2020 7:45 pm

Re: symbol '_heap' not defined

Post by cborn »

dom wrote: Mon Nov 02, 2020 9:21 am The heap needs configuring, it's easiest to go with AMALLOC which auto configures the heap: https://github.com/z88dk/z88dk/wiki/Cla ... figuration

Basically, add -DAMALLOC or -pragma-output:USING_amalloc to the command line.
I hoped for something easier then that. But i am on search&trail
There are severall (4) malloc.asm files available, but only one has a line on line 16. its the one in libsrc/alloc/malloc-classic
And in this case the line is apperently the correct line number. that file has 2 starting lines with ';' . its asm so its not seen as c without a command apperently.

if i find a way to define _heap it should work.
i'll try !
edit:
it was easy:
zcc +zx -vn malloc_test.c -o malloc_test -lndos -create-app -DAMALLOC
although it crashed after 113 inputs.
edit2:
i think it crashed becouse of the 'scroll' zone. it happens after inputing ENTER aswell, then its a DOUBLE chr since the cr and the value of the key are both printed.

so -DAMALLOC does do a good job after all
Post Reply