http://qs1969.pair.com?node_id=400297


in reply to Re^3: Ways to implement a closure
in thread Ways to implement a closure

C does not have templates OR classes! (Not that this is a bad thing...)

Replies are listed 'Best First'.
Re^5: Ways to implement a closure
by ikegami (Patriarch) on Oct 18, 2004 at 20:05 UTC
    Oops, I often call C++ by the wrong name. But while the code was C++, the argument does work for C as well. Here's the C version of the C++ snippets:
    HASH* demonstration(void* p) HASH* hash_ptr = hash_new() hash_add(hash_ptr, "demo_data", p); HASH* outer_hash_ptr = hash_new(); hash_add(outer_hash_ptr, "demonstration_data", hash_ptr); return outer_hash_ptr; }

    and

    HASH* demonstration(void* p) HASH hash; hash_init(&hash); hash_add(&hash, "demo_data", p); HASH* outer_hash_ptr = hash_new(); hash_add(outer_hash_ptr, "demonstration_data", &hash); XXX BUG return outer_hash_ptr; }