Giter Club home page Giter Club logo

c-lambda-and-callback's Introduction

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.

c-lambda-and-callback's People

Contributors

medicineyeh avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.