Loading ...
Sorry, an error occurred while loading the content.

Re: [hackers-il] Functional Programming to Become the State of the Art - ?

Expand Messages
  • Adi Stav
    ... This is a no-op. A (void*) will always remain a (void*). Remember than in C, unlike in C++, type is not a runtime quality. ... Even if up_context is a
    Message 1 of 2 , Feb 11, 2002
    • 0 Attachment
      On Mon, Feb 11, 2002 at 07:21:08AM +0200, Shlomi Fish wrote:
      >
      > void myfunc(int , void * h)
      > {
      > h = (mystruct *)h

      This is a no-op. A (void*) will always remain a (void*). Remember than
      in C, unlike in C++, type is not a runtime quality.

      > .
      > .
      > .
      > new_context = malloc(sizeof(mynewstruct));
      > new_context->up_context = h;

      Even if up_context is a pointer to a struct, this assignment is legal,
      and even without your earlier attempt to assign type information to h.
      It is a common mistake to always cast (void*) into (struct foo*), while
      in fact ANSI C guarantees a correct automatic conversion from (void*)
      to a pointer to any data type and back. Note that this automatic (void*)
      conversion feature supports your point -- it shows that having a
      reliable and convenient way to pass generic context around was deemed
      such an important feature by the ANSI C designers that it got into the
      design of an otherwise very conservative and simple language.

      > /* Fill new_context with other stuff */
      >
      > newfunc(.... , new_context);
      > }
    Your message has been successfully submitted and would be delivered to recipients shortly.