Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:19:48+00:00 2026-06-08T08:19:48+00:00

Is it possible to create a function that works on a block scope? Such

  • 0

Is it possible to create a function that works on a block scope? Such as

Edited to clarify

enum { cannot, must };
int it(enum modal verb);

describe(fx) {
    context("some context") {
        it(must) { /* Some test that returns an int to it() */ };
    }
}

I doubt this is possible so what is the next best thing I can do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:19:51+00:00Added an answer on June 8, 2026 at 8:19 am

    This looks almost like Smalltalk or Ruby to me, which makes me think you want to pass closures (sometimes called blocks) to functions. This is possible with various extensions to C, and there are also workarounds.

    For example, maybe you want to iterate over a list:

    {
        // this does not actually work, sorry
        iterate(list) { |i| -> printf("%d\n", i); }
    }
    

    If you are using Apple’s extensions to C, you can use something called “blocks”

    {
        // Apple only
        iterate(list, ^(int i) { printf("%d\n", i); });
    }
    

    You can also write a callback,

    static void my_callback(int i) { printf("%d\n", i); }
    
    ...
    {
        iterate(list, my_callback);
    }
    

    Callbacks can’t access variables in scope in other functions, so you have to figure out a way to share variables.

    And there are nested functions in GCC; these have access to scoped variables just like Apple’s “blocks” extension.

    {
        // GCC only
        void callback(int i) { printf "%d\n", i); }
        iterate(list, callback);
    }
    

    If you find yourself wanting to do this a lot, you may save yourself a lot of headache by switching to a language other than C. C is not very friendly for higher-order programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create a template function that takes a variable number of
Is it possible to create a function that returns a generic of unspecified type,
Is it possible to create an std::vector that can hold an std::function with any
I have a function that computes and create a matrix. My function works well
Is it possible to create a function out of a class method? ie. class
Is it possible to create a function which takes a pointer to another function?
It's possible to call C functions through CREATE FUNCTION but how can .NET functions
I know it's possible to create a friend function in C++: class box {
Is it possible to create a SQL Server function which returns a nullable string?
I know it is possible to create classes/objects in Perl using the bless function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.