Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Pages: 1
Hi
So Iv'e been a dev for quite a while now on web based technologies. Using very abstracted languages (C#, JS etc). Iv'e been getting frustrated with the amount of magic happening behind the curtains and the fact most people in this domain don't seem to care to know what is happening behind the curtains. So to that effect decided to try and learn something lower level for a fun project, C and Game Boy dev seemed to be a great fit.
So onto the question.
It is my rudimentary understanding that the following code snippet is perfectly valid C.
void foo(UINT8 *arg) { UINT8 bar = &arg; }
A function receives a pointer to a UINT8 value. It get the value at that location and stores it in a local variable.
However when compiling it with GBDK-2020 i get the following error
error 47: indirections to different types assignment from type 'unsigned-char generic* near* auto' to type 'unsigned-char auto'
VSCode reports no errors with its intellisense, but that's using the normal C/C++ language service which i assume is more generalized than the tooling that GBDK is using. Which leads me to believe this is something environment specific to low powered embedded devices.
Iv'e looked through (as best i can, there's lots of info) the GBDK docs about best practices with C and not seen anything that seems to be related to this.
Can anyone shed some light on what is going on here? Especially the `unsigned-char generic* near* auto` bit.
Offline
Well now i feel daft, it would appear i was missing a cast.
void foo(UINT8 *arg) { UINT8 bar = (UINT8)&arg; }
I wrongly believed that it knew the type of the value based on the type of the pointer.
Nothing like making a good first impression!
Last edited by ste2425 (2021-06-29 04:16:40)
Offline
bar = *arg;
& operator takes an address of arg itself, so result will point somewhere on stack and has a type of pointer.
Last edited by toxa (2021-06-29 08:30:02)
Offline
toxa is right, of course, but maybe it helps to explain the error message better for future problems:
The error message is a bit unclear because of all the keywords in there. What the error message is trying to tell you:
error 47: indirections to different types assignment
from type 'unsigned-char ̶g̶e̶n̶e̶r̶i̶c̶* n̶e̶a̶r̶* a̶u̶t̶o̶'
to type 'unsigned-char a̶u̶t̶o̶'
Or unsigned-char** to type unsigned-char, i.e. you try to convert a pointer to a pointer to unsigned-char directly to unsigned-char.
The generic, near and auto keywords are in there to indicate that the pointer is generic, i.e. does not point into a specific memory section, is near, i.e. uses a 16-bit address only, is automatically allocated according to ABI/calling convention (fuzzy on the last point).
Offline
Pages: 1