Translate

Archive for May, 2008

Function callbacks in C

Friday, May 2nd, 2008

Ever since I started programming in Javascript, and doing asynchronous function calls, I’ve found myself to be addicted to passing functions as parameters.

I do it a lot in python and php, it’s very easy to do this on all these dynamic typed languages.

I never had this concept of passing functions as parameters, or pointers to functions as parameters when I was a kid in school and we were doing stuff in C or Pascal, I’d deal with it with ifs and switches.

So, this afternoon I decided to read a little bit and give it a try in C.

Here’s some code for future reference If I ever need it, it’s pretty easy.

#include 
void this() { printf("This\n"); }
void that() { printf("That\n"); }

int sum(int x, int y) {	return x+y; }

int mul(int x, int y) { return x*y; }

//Function that takes a callback that uses no parameters
void callanother(void (*callback)()) {
  (*callback)();
}

//Function that takes a callback that
//takes 2 int parameters and returns int
int callComplexCallback(int (*callback)(),int a, int b) {
  return (*callback)(a,b);
}

int main (int argc, char** argv) {
  callanother(this);
  callanother(that);

  printf("\n");

  int w = 20;
  int h = 30;

  printf("%d\n",callComplexCallback(sum,w,h));
  printf("%d\n",callComplexCallback(mul,w,h));

  //this also works
  printf("%d\n",callComplexCallback((*sum),w,h));
  printf("%d\n",callComplexCallback((*mul),w,h));

  return 0;
}

The output is this:

~$ ./a.out
This
That

50
600
50
600

The whole trick is how you define the function that will take the other function as a parameter.

If you have a function:

void whatever();

The function that’s supposed to use “whatever()” like-functions should look:

void useWhateverLikeFunctions(void (*f)()) {
  ...
  (*f)();
}

If you have a callback function that needs parameters, then you define the caller as:

void callerFunction(void (*f),int paramA, int* paramB, char paramC) {
  ...
  (*f)(paramA,paramB,paramC);
}

Then you’d use the function

void someCallback(int a, int* b, char c);

...
callerFunction(someCallback,a,b,c);
...

I know this is the oldest thing in the world to C programmers, but it never crossed my mind before, so here it is for my own personal reference, I hope it serves others.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

DJ Afro – Will Work for Fun

Friday, May 2nd, 2008

DJ Afro is Jose Luis Pardo, the venezuelan guitar player, prodigy musician and composer of Los Amigos Invisibles.

This playlist is courtesy of El Blogo who could find this album somewhere in Mexico and was kind enough to share it with us at MyBloop.com

About DJ Afro (taken from his official website)

DJ Afro (A.K.A. Jose Luis Pardo)

If you go to a Los Amigos Invisibles (LAI), you will never listen to any Shakira or Enrique Iglesias because DJ Afro, the band’s guitar player, is in charge of heating up the party and making sure the night starts well enough to move your feet with really funky rhythms.

Time has passed and Dj Afro (a.k.a Jose Luis Pardo) has managed to get the party going even when LAI are not playing after him.

He is responsible for writing more than 80% LAI’s music, as well as playing guitar, keyboard and background vocals for all five albums. He has also been featured on Louie Vega’s “Elements of life” and Dimitri from Paris’ “Cruising attitude”.

Aside from his work with the band, DJ Afro also enjoys a respected career as a remix producer. He just released his first solo track, “Mala Idea” (look at you records). He has published several remixes for Dimitri from Paris, and in his remix’ reel you can find tracks of Beastie Boys, Fantastic Plastic Machine, David Byrne, Radio Zumbido, Fundación Tony Manero, Sonorama, Soul Coughing, Los Amigos Invisibles, John Scofield and others.

As a DJ with a bag full of records that can go from Samba to Boogaloo, from Rare Grooves to Organic House to Disco, he can make people smile and start dancing almost anywhere.

DJ Afro has been spinning all around New York City since he moved here. He has been a guest behind the decks in parties like Turntables on the Hudson, Giant Step, PS-1, Shelter, Cielo, Suba, Remote lounge, Nublu, Pink (SF), Knitting Factory (LA), La santanera (playa del Carmen), O bar (Dallas), Sala Arena (Madrid), The Basement (Australia) and others. He has opened for Dimitri from Paris and Little Louie Vega. Nowadays, DJ Afro’s afterparties in local clubs following LAI’s gigs are becoming a standard in every city they perform.

Afro is also part of expansion team, a prestigious agency of top of the line producers that create music for commercial spots and films. He has produced original music for brands like Mazda, Sears, Miller, General Motors, AT&T and Sony, among others.

He was also the mind behind CHILL OUT VENEZUELA (Gozadera Records, 2004), a compilation featuring the new scene of young Venezuelan producers that has been very well received by music lovers. He is now finalizing details on its follow up, “DANCE VENEZUELA”.

DJ Afro recently composed the soundtrack for “Sed en los Pies,” a short film that opened in Venezuela in late 2005, and he will be working on the music for Mexican director Luis Sanchez’ new film. Afro’s music will also accompany Crimanesa Amoroso’s new art piece.

For the past two years, he has recorded a weekly radio show, DJ AFRO Y SU RUMBA BARATA, which airs in Caracas every Friday on ATENEO 100.7 FM, with great feedback. Afro is also in charge of choosing the playlists at SUBA, one of the most prestigious restaurants in downtown Manhattan.

Jose Luis also has a life as a journalist. He writes a column for two magazines: PLAY (Venezuela) and EL HUEVO (México) and he contributes frequently to other Venezuelan magazines like TODO EN DOMINGO and URBE.


More About DJ Afro
You can read his curious blog (in spanish) at http://elafro.com/blog/, which he seems to often update whenever he sits at the airport, given the titles of “Airport Chronicles” in some of his posts.

Support this artist if you enjoyed this playlist.

Pictures courtesy of Juan Galvan Adriana Gutierrez Varela

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Tecnotulia: Evolucion del Video e Internet TV

Friday, May 2nd, 2008


For more funny videos, click here

Jose Manuel de Tecnotulia.com y Angel Leon wedoit4you.com hablan en detalle de la evolucion de la distribucion de video en internet, con un estilo al honor del podcast DiggNation

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

emacs doesn’t work after Leopard upgrade?

Friday, May 2nd, 2008

After updating from Tiger to Leopard I started getting this error whener I tried to execute emacs:


Fatal malloc_jumpstart() error

The solution was basically to reinstall it with dumpemacs


sudo mv /usr/bin/emacs-i386 /usr/bin/emacs-i386.backup
sudo /usr/libexec/dumpemacs -d
emacs --version
emacs

Via Apple Support Discussions

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Baby Stress Test – The Indian Baby Drop Ritual

Friday, May 2nd, 2008

Sick level funny ritual.

I thought you’re not supposed to even shake a baby when it’s crying, I guess this is to stress test them, holy shit.

This is a ritual that’s been around for 500 years, the video was shot in Solapur, India.
The purpose seems to be having the babies grow strong. It seems to me more like a stress test, you either break or you make it.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)


  • Categories

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • October 2009
  • September 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004