R
Ruud Baltissen
Hello,
I have decided to port some Turbo Pascal programs to C/C++. Most of them are Commodore related, for example: a drive simulator, and should run under DOS. I have developed various units and I have troubles converting them to C.. Not converting the code itself but defining the .h files and using them.
I have one unit, RB_unit.pas, that contains general functions, for example:deleting the white space at both ends of a string. A second one, CBM_unit.pas only contains Commodore related functions, for example: a function to read a byte from the IEEE bus. The main program can call functions from bothRB_unit and CBM_unit. CBM_unit can call functions from RB_unit as well. Inboth units I declared some global variables. In cbm_unit.h I declared a structure with drive properties. In CBM_unit.pas I declared:
Device : array[0..coMaxDevice] of ^TEmuDevice;
I translated this to:
struct EmuDeviceStr Device[coMaxDevice];
What did I do more: I declared 'byte' in RB_unit.h. I don't know if I keep it but for the moment I use it to learn how to work with .h files.
I also declared a constant there: const char chcsep = '/';
The problems:
If I write the next text in the main function, everything is allright:
byte b1, b2;
struct EmuDeviceStr Device[coMaxDevice];
for (b1 = 0; b1 < coMaxDevice; b1++)
for (b2 = 0; b1 < 2; b1++)
Device[b1].Drv[b2].InUse = False;
But if I write it in a (now empty) function in CBM_unit.c, I get errors. The first one is that cbm_unit doesn't know 'byte'. Quite logical, because I didn't include rb_unit.h yet. But if I include it, I get several errors. I deleted the 'for' construction but then got this error: "multiple definition of `chcsep'".
Commenting out this const declaration worked again (except two warnings notusing B1 and b2) but then my question: what do I wrong or where should I declare this const then?
Adding 'for' construction again produced the several error; both 'coMaxDevice' and 'Device' are undeclared. Both have been declared in cbm_unit.h. So I included cbm_unit.h but that resulted in more "multiple definition" errors
Next problem: I know I have to declare 'struct EmuDeviceStr Device[coMaxDevice];' somewhere outside 'main', IMHO in cbm_unit.c. But if I do I get the error "variably modified 'Device' at file scope".
I can only say now: PLEASE, HELP !!!
Many thanks in advance!
Kind regards, Ruud Baltissen
www.Baltissen.org
I have decided to port some Turbo Pascal programs to C/C++. Most of them are Commodore related, for example: a drive simulator, and should run under DOS. I have developed various units and I have troubles converting them to C.. Not converting the code itself but defining the .h files and using them.
I have one unit, RB_unit.pas, that contains general functions, for example:deleting the white space at both ends of a string. A second one, CBM_unit.pas only contains Commodore related functions, for example: a function to read a byte from the IEEE bus. The main program can call functions from bothRB_unit and CBM_unit. CBM_unit can call functions from RB_unit as well. Inboth units I declared some global variables. In cbm_unit.h I declared a structure with drive properties. In CBM_unit.pas I declared:
Device : array[0..coMaxDevice] of ^TEmuDevice;
I translated this to:
struct EmuDeviceStr Device[coMaxDevice];
What did I do more: I declared 'byte' in RB_unit.h. I don't know if I keep it but for the moment I use it to learn how to work with .h files.
I also declared a constant there: const char chcsep = '/';
The problems:
If I write the next text in the main function, everything is allright:
byte b1, b2;
struct EmuDeviceStr Device[coMaxDevice];
for (b1 = 0; b1 < coMaxDevice; b1++)
for (b2 = 0; b1 < 2; b1++)
Device[b1].Drv[b2].InUse = False;
But if I write it in a (now empty) function in CBM_unit.c, I get errors. The first one is that cbm_unit doesn't know 'byte'. Quite logical, because I didn't include rb_unit.h yet. But if I include it, I get several errors. I deleted the 'for' construction but then got this error: "multiple definition of `chcsep'".
Commenting out this const declaration worked again (except two warnings notusing B1 and b2) but then my question: what do I wrong or where should I declare this const then?
Adding 'for' construction again produced the several error; both 'coMaxDevice' and 'Device' are undeclared. Both have been declared in cbm_unit.h. So I included cbm_unit.h but that resulted in more "multiple definition" errors
Next problem: I know I have to declare 'struct EmuDeviceStr Device[coMaxDevice];' somewhere outside 'main', IMHO in cbm_unit.c. But if I do I get the error "variably modified 'Device' at file scope".
I can only say now: PLEASE, HELP !!!
Many thanks in advance!
Kind regards, Ruud Baltissen
www.Baltissen.org