So- here's a C language question that reflects my lack of understanding of C- is it possible to define a variable-length string (aka character array) in a structure? (Specifically, in the GNU C implementation used by TIGCC/GCC4TI).
That's the basic question- here's why I want to know:
I have this structure defined in Solar89 (Comments should describe what each item is for):
typedef struct
{
size_t chars; // How many chars are in the string making up the token
int twoByteToken; // Whether or not the token is two bytes (0 or 1)
unsigned char hex[2]; // The two bytes making up the token, or only hex[0] if it's a one-byte token
char name[14]; // The name of the token (never more than 14 chars!)
} tokenInfo;
The way Solar89 currently works is that it reads in a text file and creates an array of these structures. This allows an editable database to store tokens, but it means the initialization will be slow.
I decided I could make it faster by making a second program that does the same thing and writes that array directly to a file. In theory (and correct me if I'm wrong- if I am this entire question is irrelevant) I could read the tokens in much faster by just doing something this (with size being the length of the file, or something like that):
fread(tokens, size, sizeof(tokenInfo), file);
Well, I tested the "token file compiler". The token file outputted is about twice the size as the text file is- for a 5000 byte file, it's around 11000 bytes. Now, this might be worth it if it made the process much faster- I haven't tested that though.
I suspect I could get rid of some space if I could shrink down tokenInfo.name when the token name was only "A" or "1" or "prgm"... etc. But I don't know how to do that.
Is this clear? If not, please just go back to the first paragraph for the actual question and try to ignore the context.