Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory functions not working. #18

Closed
SeedyROM opened this issue Feb 17, 2017 · 4 comments
Closed

Memory functions not working. #18

SeedyROM opened this issue Feb 17, 2017 · 4 comments

Comments

@SeedyROM
Copy link

SeedyROM commented Feb 17, 2017

Upon compiling all of the memory allocation, etc. functions aren't defined.
I'm not entirely sure why, but this is what I get in the console.

main.c(67):warning *** function 'memset' implicit declaration

main.c(78):warning *** function 'free' implicit declaration

main.c(82):warning *** function 'malloc' implicit declaration

Is this just a weird bug on my end?

@gheja
Copy link
Owner

gheja commented Feb 17, 2017

Which compiler (and version) are you using? Also on what platform?

@SeedyROM
Copy link
Author

SeedyROM commented Feb 18, 2017

I'm currently running it under Ubuntu 16.04, 64-bit AMD.
Here's my version information for the compilers.

-> % lcc -v
lcc $Id: lcc.c,v 1.6 2001/10/28 18:38:13 michaelh Exp $
-> % sdcc -v
SDCC : gbz80/z80 2.3.1/gbdk-2.96a (Feb 14 2017) (UNIX)

I wrote a test program to showcase what I'm experiencing, maybe I'm just an idiot and I'm missing something huge.

#include <stdio.h>     // For debug.
#include <stdlib.h>    // Shouldn't malloc be included here?
#include <gb/gb.h>
#include <gb/malloc.h> // Doesn't throw an error finding the header file.
                       // But nothing gets defined.


// Stupid simple struct.
typedef struct _object {
  UBYTE  x,  y;
  BYTE  vx, vy;
} object;

void main() {
  object *obj = (object *)malloc(sizeof(object)); // Implicit delcaration?
  printf("%d", sizeof(obj));
}

If i compile it with lcc -v -c main.c this is the console output I get:

lcc $Id: lcc.c,v 1.6 2001/10/28 18:38:13 michaelh Exp $
/opt/gbdk/bin/sdcpp -Wall -lang-c++ -DSDCC=1 -DSDCC_PORT=gbz80 -DSDCC_PLAT=gb -DSDCC_MODEL_SMALL -DGB=1 -DGAMEBOY=1 -DINT_16_BITS -D__LCC__ -I/opt/gbdk/include main.c /tmp/lcc45600.i
/opt/gbdk/bin/sdcc -mgbz80 --noinvariant --noinduction --nostdinc --nostdlib --model-small --c1mode /tmp/lcc45600.i /tmp/lcc45601.asm
main.c(15):warning *** function 'malloc' implicit declaration
main.c(15):error   *** too many parameters 
main.c(15):warning *** function 'malloc' implicit declaration
main.c(16):error   *** code not generated for 'main' due to previous errors
lcc: fatal error in /opt/gbdk/bin/sdcc
rm /tmp/lcc45601.asm /tmp/lcc45600.i

Hope that's enough info.

@gheja
Copy link
Owner

gheja commented Mar 18, 2017

Thanks for the example. Yes it seems that the malloc.h does not contain the declaration of malloc(), you might need to use gbdk-lib/libc/malloc.c.

I am not really familiar with the code but I could not find usage of malloc() in any of the example codes. In malloc.h there is a comment saying "Header for a simple implementation of malloc(). This library may currently be broken.".

There is a newer version of gbdk called gbdk-n but the malloc.h is the same.

@SeedyROM
Copy link
Author

SeedyROM commented Mar 18, 2017

Yeah, I realized this after a dig through the source code not long after I sent this issue.

Thank you for getting back in touch though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants