The problem occurs when one structure, TPARAMS, points to another structure, XUNDO2, and that structure points to a short table, xnewstep[], which points to yet another structure, ELEMENT. But the pointer to XUNDO2 can also point to XUNDO1 or XUNDO3, so it is defined as a void* pointer.
Since THAT pointer is NOT defined as struct XUNDO2*, the compiler doesn't know where to find the xnewstep table. I want to use a type cast to say, in this case, the pointer indeed points to an XUNDO2 structure.
Code: Select all
struct XUNDO1
{struct ELEMENT* xnewstep[9];
struct ELEMENT* xoldstep[9];
char xvalue[9];};
struct XUNDO2
{struct ELEMENT* xnewstep[9];};
struct XUNDO3
{struct ELEMENT* xpostreq[100];};
struct TPARAMS
{short int action;
char kind;
char newtsnum[6];
char newstat;
struct ELEMENT* newtask;
struct ELEMENT* oldtask;
struct ELEMENT* addpoint;
struct ELEMENT* topstep;
struct UNDO* unthing;
void* /* points to the extended undo area; this could */
xthing;}; /* be the structure XUNDO1, XUNDO2, or XUNDO3 */
struct ELEMENT
{struct ELEMENT* chain1;
struct ELEMENT* chain2;
struct ELEMENT* chain3;
short int duetime;
short unsigned int duedate;
char status;
char priority[2];
char tasktype;
char tasknum[4];
char stepnum;
char descript[2];};
void edittask(struct ELEMENT* origtask)
{struct TPARAMS t;
. . .
{t.oldtask = ((struct XUNDO2*)t.xthing)-> xnewstep[i]; /* WORKS FINE */
. . .
baseopts(&t);
. . .
void baseopts(struct TPARAMS* t)
. . .
{addopts(descbuf, t);
. . .
void addopts(char descbuf[], struct TPARAMS* t)
. . .
{if ((struct XUNDO2*)t-> xthing-> xnewstep[s] != 0) break;};
. . .
When I compile this, I get Warning . . . 'xnewstep' not part of structure in function addopts .
I want to be able to use the type cast "(struct XUNDO2*)" to let the compiler know I'm pointing to an XUNDO2 structure -- but I can't seem to figure out exactly where to put it.
I can work around this problem by assigning t-> xthing to a temporary variable then type casting that, or by redefining xthing as a struct XUNDO2* variable. But either of these solutions would reduce the readability of the program.
I've googled type casts and pointers, but nothing I found covers this exact situation.
I'm using Turbo C and running the binary under DOSBox under Debian Stretch with the MATE desktop. (Later on, I will rewrite this in a more modern language.) But if someone can give me a syntax that works under gcc, I'll accept that as solution to the problem.
Caitlin