cast to void pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    cast to void pointer

    How many cast can be used on void pointer
  • Victor Bazarov

    #2
    Re: cast to void pointer

    puzzlecracker wrote:
    How many cast can be used on void pointer
    Infinitely many:

    int main()
    {
    char const str[] = "abc";
    void ptr = str;
    while (true) // infinitely long
    {
    char const *pchar = static_cast<cha r const*>(prt);
    }
    }

    The pointer when cast to another, does not degrade or affect the system.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    • blargg

      #3
      Re: cast to void pointer

      In article
      <aa4c069c-f880-4276-89ae-f6c39ccdd829@d7 0g2000hsc.googl egroups.com>,
      puzzlecracker <ironsel2000@gm ail.comwrote:
      How many cast can be used on void pointer
      As many as you can imagine (for practical purposes, infinite):

      void* p = 0;
      static_cast<cha r*(p);
      static_cast<cha r**(p);
      static_cast<Foo *(p);
      static_cast<int (*) [1](p);
      static_cast<int (*) [2](p);
      etc.

      Comment

      Working...