Skip to content

This is a novel way to improve coding style of your project by adopting lambda expression and callback function.

License

Notifications You must be signed in to change notification settings

MedicineYeh/C-Lambda-and-Callback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C-Lambda-and-Callback

Lambda expression has been supported by many programing languages. But it is not supported by standard C. This problem is now solved by the combinations of some techniques. If you want to have the same functionality of lambda, your compiler needs to support nested function. The result would be something like this:

my_qsort(values, 6, a, b, return (*(int*)a - *(int*)b););

If you only needs a callback function, there's no extra requirements. it can be compiled by almost every C compiler. The result is like this:

pop_job(job_semaphore,
    //In callback function
    //This is for double check, preventing unexpeted bug
    while(isBufferEmpty(buffer_t));
    bufferRead(buffer_t, p);
    printf("\tpop %d, %d\n", p.x, p.y); //Print message
);

Compilation

  • gcc -lpthread ./pthread.c -o ./pthread
  • gcc ./lambda.c -o ./lambda

Usage and Description

Please reference to my blog

Super Fast Ring Buffer

This is my version of Ring Buffer modified from Philip Thrasher I made macros deal with only pointer type for easier to use.

About

This is a novel way to improve coding style of your project by adopting lambda expression and callback function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages