void *MyConfigDetail; if (x) { ((TType1 *) MyConfigDetail) = DetailCacheBeans; } else { ((TType2 *) MyConfigDetail) = DetailailCacheHam; } </rpr> But I am unable to access the "MyConfigDetail" elements as MyConfigDetail->Forks = 22; // for example Why not?
You said
"Are you happy with casts littering your code when not required...?"
I'm happy. my code works. Yehoooaah.
"I'm happy. my code works. Yehoooaah."
If a school assignment, then the teacher should request a rewrite or give out a "fail".
Typecasts from void pointers is required - for example to implement abstract data types. Bad use of language constructs is a big reason why so much everyday equipment regularly fail because of sw errors. Don't be happy if you get a couple of lines through the compiler. Be happy when you have a program that is well tested and easy to maintain.
Would you be happy if the car mechanic fixes your car with duct tape? If the plumber fixes your sink with a chewing gum? Right now, you are that plumber...