Re: [hackers-il] Functional Programming to Become the State of the Art - ?
- On Mon, Feb 11, 2002 at 07:21:08AM +0200, Shlomi Fish wrote:
>This is a no-op. A (void*) will always remain a (void*). Remember than
> void myfunc(int , void * h)
> h = (mystruct *)h
in C, unlike in C++, type is not a runtime quality.
> .Even if up_context is a pointer to a struct, this assignment is legal,
> new_context = malloc(sizeof(mynewstruct));
> new_context->up_context = h;
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);