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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:30:18+00:00 2026-05-14T18:30:18+00:00

So I was wondering how they work. To explain what I mean by a

  • 0

So I was wondering how they work. To explain what I mean by a “function caller” a good example of what I mean would be glutTimerFunc, it is able to take in a function as a parameter and call it even with it not knowing it is declared. How is it doing this?

  • 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-14T18:30:18+00:00Added an answer on May 14, 2026 at 6:30 pm

    What you’re talking about is called a callback and is implemented with function pointers in C and C++.

    Since you mentioned glut, let’s take a real example directly from the freeglut source code. I’ll use glutIdleFunc instead of glutTimerFunc because the code is simpler.

    In glut, the idle function callback (what you supply to glutIdleFunc) is a pointer to a function that takes no parameters and returns nothing. A typedef is used to give such a function type a name:

    typedef void (* FGCBIdle)( void );
    

    Here, FGCBIdle (short for FreeGlut CallBack Idle) is defined as a pointer to a function that takes no parameters and whose return type is void. This is just a type definition that makes writing expression easier, it doesn’t allocate any storage.

    Freeglut has a structure called SFG_State that holds various settings. Part of the definition of that structure is:

    struct tagSFG_State
    {
        /* stuff */
        FGCBIdle         IdleCallback;         /* The global idle callback       */
        /* stuff */
    };
    

    The struct holds a variable of type FGCBIdle, which we established is another name for a specific function pointer. You can set the IdleCallback field to point to the address of a function that is supplied by the user using the glutIdleFunc function. The (simplified) definition of that function is:

    void glutIdleFunc( void (* callback)( void ) )
    {
        fgState.IdleCallback = callback;
    }
    

    Here, fgState is a SFG_State variable. As you can see, the glutIdleFunc takes one parameter which is a function pointer to a function that takes no parameters and returns nothing, this parameter’s name is callback. Inside the function, the IdleCallback inside the global fgState variable is set to the user supplied callback. When you call the glutIdleFunc function, you pass the name of your own function (e.g. glutIdleFunc(myIdle)), but what you’re really passing is the address of the function.

    Later, inside the big glut event processing loop initiated by glutMainLoop, you’ll find this code:

    if( fgState.IdleCallback )
    {
                /* stuff */
                fgState.IdleCallback( );
    }
    

    If a user supplied idle callback is available, it is called in the loop. If you check the function pointer tutorial at the beginning of my post you will understand the syntax better, but I hope the general concept makes more sense now.

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

Sidebar

Related Questions

i'm wondering how does the media servers work, do they require large bandwidth if
I am wondering why did they design the toArray method in ArrayList to take
I'm wondering if these two expressions are equivalent, because if they are, it would
I was wondering how would one create a javascript function for transposing music chords.
I was wondering how check boxes work in Rails? What would the table be
I was wondering how they fixed this kind of effect: On scroll to <div
I was wondering if anyone had an opinion on what they think is the
I was wondering if it is possible to give people something when they join
They changed some things with Xcode 4, so I was wondering if I needed
I was wondering how I give the user the new add-ons after they purchase

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.