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 7685499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:15:53+00:00 2026-05-31T19:15:53+00:00

I think that some newer languages like JS can do this natively, but I

  • 0

I think that some newer languages like JS can do this natively, but I forget the term for it (make a “temporary” function in-line just to pass as a callback)

What I want to do is …

I’m writing unit tests where I set up expected input & output messages at compile time. Later at run time, I want to do some checks when each output is received or input has been processed, so I added a parameter for a callback function.

That’s working fine and I could leave it & move on, but … I am just curious …

sometimes a function is overkill and I just need a single comparison; sometime a small block of code would do. Perhaps I could just evaluate these to a zero/non-zero value at run time? But how to pass as a parameter?

At the moment my function has the following signature

void AddExpectedCommand(E_peripheralType peripheral, 
                        communicationBlock_t commandBlock, 
                        errorMessage_t errorMessage, 
                        void *(*DoRunTimeChecks)(E_boolean));

where the final parameter is pointer to a callback function returning boolean.

Is there any way that I could pass a code expression as a parameter instead?

Or does a function seem “cleaner”?

Thanks in advance for any help …


Update: oops, I got my declaration wrong. I want to pass a pointer so a function which has no parameters and returns an e_Boolean … how do I do that?

  • 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-05-31T19:15:54+00:00Added an answer on May 31, 2026 at 7:15 pm

    With C++11 you can do the following:

    Function taking a function that returns a bool:

     void f(function<bool()>);
    

    Call it with a lambda capturing a local variable:

     int x = ...;
    
     f([&x]() { return (x > 2); });
    

    Or call it with some function g that returns a bool:

    bool g();
    
    
    f(g);
    

    Or bind some function h that takes an int and returns a bool:

    bool h(int x);
    
    
    f(bind(h, 2));  // ie creates a nullary function from h(2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to think that some of the software I'm writing today will
I'm familiar with some mnemonic/memorization techniques for about a year. I think that this
Hi all I am having some problems that I think can be attributed to
I think I read somewhere that some modules only have object oriented interfaces (
Some of the fellows in the office think that when they've added threads to
O.K. I think that's an easy one! I have a ViewMasterPage with some links
I have some data that I have to display as a table. I think
After messing about with F# there are some really nice features that I think
Sometimes it's difficult to describe some of the things that us programmers may think
I had some experience on programming languages like Java, C#, Scala as well as

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.