This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can someone advice for pointers for void objects?

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?


Parents
  • A void pointer doesn't have a type. So it obviously don't have any elements. Assigning something to a void pointer means that you are throwing away all type information.

    But this is not specific to embedded systems - do look in a good book on C or C++ programming.

    And don't use any void pointers unless you really need them. The more specific data types you are using on your variables, the easier it will be to keep track of the meaning of the variable and how you may use it. void is the maximum generic you can find, so it is the #1 way to make sure that the compiler will not be able to help you.

    No not use void pointers unless you know how to use C and how to use "normal" pointers. And with know, I mean "really know".

Reply
  • A void pointer doesn't have a type. So it obviously don't have any elements. Assigning something to a void pointer means that you are throwing away all type information.

    But this is not specific to embedded systems - do look in a good book on C or C++ programming.

    And don't use any void pointers unless you really need them. The more specific data types you are using on your variables, the easier it will be to keep track of the meaning of the variable and how you may use it. void is the maximum generic you can find, so it is the #1 way to make sure that the compiler will not be able to help you.

    No not use void pointers unless you know how to use C and how to use "normal" pointers. And with know, I mean "really know".

Children