A89: Re: Help, why won't it compile in nostub mode?


[Prev][Next][Index][Thread]

A89: Re: Help, why won't it compile in nostub mode?




Hi!

> I know it doesn't work, but why doesn't it compile in 
> nostub mode?

Because in "nostub" mode all global variables (e.g. variables
which are defined out of any functions) MUST be initialized.
Uninitialized globals are stored on BSS which is not support
in TIOS itself, only in Doors. That's why uninitialized globals
doesn't work in "nostub" mode.

You have a lot of such variables. See, if X is a global,
instead of

int X;

you need to write

int X=0;

even if you don't need to have an intitial value. If you
want to have global array, instead of

int A[10];

you need to write

int A[10]={0,0,0,0,0,0,0,0,0,0};

or simply (this is the same):

int A[10]={};

But, having a large global (initialized) array have a big
drawback: increasing size of .89z file, because INITIALIZED
global arrays are stored in the file itself. So if you have
global declaration

int A[5000]={};

you will increase size of your file by 10K (5000*sizeof(int)).

What to do? Use locals as much as possible. But, if you need 
to have big global arrays, use dynamic allocation. Instead of

int A[5000]={};

use

int *A=NULL;

Then, you need to do (at the begining of your main program):

A=calloc(5000,sizeof(int));

to allocate 5000 elements to array A. See also FAQ list given
with TIGCCLIB. I hope that I am clear enough.

Cheers,

Zeljko Juric