Home > Articles > Programming > C/C++

  • Print
  • + Share This
This chapter is from the book

Exercises

  1. Rewrite this function as a block:

    int k(void) {
        return 1;
    }
  2. Write a function create_k that accepts a single integer argument i and returns a block. The returned block accepts no arguments and always returns the value of i passed to create_k(). Use this function in a test program. (Be careful with the block memory management!)

  3. Define two blocks called add_one and add_two that accept no arguments and return nothing. These should both increment the same integer by one or two. (You will need the __block storage specifier.)

  4. Use typedefs to simplify the following block reference declaration:

    int (^(*(^get_block_factory_funcptr)(void))(int))(void);
  • + Share This
  • 🔖 Save To Your Account