Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Common Lisp in C

Name: Anonymous 2012-10-03 17:23

Lets write Common Lisp functions in generic C code.


/* (map #'func array) => map(array,length_of_array,sizeof(array),function_pointer) */
void *map(void *base,size_t len,size_t elemnsize, void (*func)(void *,void *)) {
  void *b = malloc(elemsize*len);
  size_t i;
  for(i=0;i<len;++i){
    func(b+(elemsize*1),base);
    base += elemsize;
  }
  return b;
}

Name: Anonymous 2012-10-05 19:49

>>23
This isn't what he's suggesting, that is what I am suggesting.

>>24
Can i use this in C89/99?
You can use the map macro, but you won't really gain any thing over just a for loop. You obviously can't use the nested function thing, that's GCC specific.

How does gcc handle scope names if i named another variable _i when using the that?
Just like it would any other scope, it works fine.

>>26
It's O(n) slower than not doing anything at all, and this is noticeable  when you don't have to do it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List