I have that updated document (it's actually integrated in the SPC_TXT file that comes with Digital C SE distribution).
So I've narrowed down the problem. It's not an issue with 2D arrays, it's actually an issue with array of structs. So this code will work:
Code: Select all
#include stdio_h
struct record {
int a;
int b;
};
struct record list[10];
main ()
{
list[5].a = 10;
list[5].b = 20;
printf("%d, %d\n", list[5].a, list[5].b); /* works using literal values...prints 10 and 20 */
}
But as soon as you introduce variables it will not:
Code: Select all
#include stdio_h
struct record {
int a;
int b;
};
struct record list[10];
int i; /* global variable */
main ()
{
int j; /* local variable */
i = 5;
j = 5;
list[5].a = 10;
list[5].b = 20;
printf("%d, %d\n", list[i].a, list[j].b); /* doesn't work using variables (doesn't matter if local or global)...prints 0 for both */
}
Of course if you use i and j during the assignment then it works but only because you are accessing uninitalized memory (i.e. for me I'd see some screen corruption). Looking at the addresses, anytime you have a variable as an array subscript, when using an array of structs, it calculates the offset but doesn't add it to the actual address -- so all you are left with is the offset.
I do have the source (from Dilwyn's site) and I emailed Gerry Jackson, who is still active on GitHub. Unfortunately the email he used for Digital C SE is specific to it (
qldigitalc@gmail.com) so I may not hear from him. I can't find his email on GitHub, though I could just randomly post/comment on an active project and see if he responds. The Digital C SE source was compiled on QL2K using Digital C SE (pretty cool) so I should be able to create a corrected version if I can figure out where it fails. It's in the parser, and having it narrowed down to the simplest case will hopefully make it easier to figure out.
What I need to do first is compile my sample code on other emulators in case QLAY is doing something funky that's causing this weird issue. I also want to make sure I have the latest version of Digital C SE, in case an older version crept in for me. I'm still hesitant to say there is a bug in Digital C SE, because if it is a bug, that would have been horrible QA by Digital Precision. They basically implemented this struct feature that made it unique from all the other Small C implementations on the QL (i.e. GSC and QL Small C) and failed to check if it actually fully worked...and they specifically had examples in their manual using that feature.