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

  • Home
  • SEARCH
  • 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 9200249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:43:24+00:00 2026-06-17T22:43:24+00:00

The pointers function declarations in the following snippets of code allows me to vary

  • 0

The pointers function declarations in the following snippets of code allows me to vary the names of each function inside the struct, correct? This is merely hypothetical, so the names are of no consequence yet.

Header File

typedef struct
{
    bool (*enabled)(uint32_void);
    void (*start)(uint32_t);
    void (*stop)(uint32_t);
    bool (*expired)(void);
} battle_star_gallactica;

C File

static bool Battle_v0_enabled (void) { ... }
static void Battle_v0_start (uint32_t) { ... }
static void Battle_v0_stop (uint32_t) { ... }
static bool Battle_v0_stop (void) { ... }

const battle_star_gallactica battle_v0 =
{
    enabled,
    start,
    stop,
    expired
};
...

One Example Use

battle_v0.start(1000);

The C file snippet would be repeated for other versions (e.g. v1 or v2 instead of v0).

How does this work?

EDIT

Corrected code:

Header File

typedef struct
{
    bool (*enabled)(uint32_void);
    void (*start)(uint32_t);
    void (*stop)(uint32_t);
    bool (*expired)(void);
} battle_star_gallactica;

extern const battle_star_gallactica battle_v0;
extern const battle_star_gallactica battle_v1;
...

C File

static bool Battle_v0_enabled (void) { ... }
static void Battle_v0_start (uint32_t val) { ... }
static void Battle_v0_stop (uint32_t val) { ... }
static bool Battle_v0_expired (void) { ... }

const battle_star_gallactica battle_v0 =
{
    Battle_v0_enabled,
    Battle_v0_start,
    Battle_v0_stop,
    Battle_v0_expired
};
...

One Example Use

battle_v0.start(1000);
  • 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-17T22:43:26+00:00Added an answer on June 17, 2026 at 10:43 pm

    Yes. But you have a few issues:

    1) Battle_v0_stop is defined twice
    2) When initing battle_v0 you need to prefix values with Battle_v0_

    You could then do:

    battle_v0.enabled()
    

    But I would have currnet battle star galactic and use it:

    const battle_star_gallactica bsg = battle_v0;
    bgs.enabled()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this sample code in an answer to How do function pointers in
I can create function pointers in Fortran 90, with code like real, external ::
I'm trying to store member function pointers by templates like this: (This is a
I'm trying to create a map of function names and function pointers using __stdcall.
Following code has to be used in the main-function, but I don't know how
Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void
I have a function pointer inside a struct that gets dynamically set at runtime
I have written the following C99 code and was wondering about the struct declaration.
What is faster: Function pointers or switch? The switch statement would have around 30
I am trying to understand function pointers and am stuggling. I have seen the

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.