| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | void pointers |
HS> I thought I could just do a simple cast to the
HS> structure + 1 (the extra byte is where the TYPE lies)
You don't need the +1.
typedef struct { char type, name[16]; long stats[16]; } PERSON;
typedef struct { char type, label[16]; float status; } OBJECT;
void ShowStatus(void *Obj)
/* Show object status or person hit points */
{
switch(*((char*)Obj))
{
case 'p':
printf("Hit Points: %dl", ((PERSON*)Obj)->stats[0]);
break;
case 'o':
printf("Status: %f", ((OBJECT*)Obj)->status);
break;
default: break;
}
}
Your structure, as defined, takes the extra char into account
already, and relies on its being there when calculating the
other members' positions within the data block and values.
> ] * Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)SEEN-BY: 396/1 632/0 371 633/260 267 270 371 634/397 635/506 728 810 639/252 SEEN-BY: 670/218 @PATH: 154/750 222 396/1 633/260 635/506 728 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.