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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:11:18+00:00 2026-05-20T17:11:18+00:00

I have a struct that contains a declaration like this one: void (*functions[256])(void) //Array

  • 0

I have a struct that contains a declaration like this one:

void (*functions[256])(void) //Array of 256 functions without arguments and return value

And in another function I want to define it, but there are 256 functions!
I could do something like this:

struct.functions[0] = function0;
struct.functions[1] = function1;
struct.functions[2] = function2;

And so on, but this is too tiring, my question is there some way to do something like this?

struct.functions = { function0, function1, function2, function3, ..., };

EDIT: Syntax error corrected as said by Chris Lutz.

  • 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-20T17:11:18+00:00Added an answer on May 20, 2026 at 5:11 pm

    I have a struct that contains a declaration like this one:

    No you don’t. That’s a syntax error. You’re looking for:

    void (*functions[256])();
    

    Which is an array of function pointers. Note, however, that void func() isn’t a “function that takes no arguments and returns nothing.” It is a function that takes unspecified numbers or types of arguments and returns nothing. If you want “no arguments” you need this:

    void (*functions[256])(void);
    

    In C++, void func() does mean “takes no arguments,” which causes some confusion (especially since the functionality C specifies for void func() is of dubious value.)

    Either way, you should typedef your function pointer. It’ll make the code infinitely easier to understand, and you’ll only have one chance (at the typedef) to get the syntax wrong:

    typedef void (*func_type)(void);
    // ...
    func_type functions[256];
    

    Anyway, you can’t assign to an array, but you can initialize an array and copy the data:

    static func_type functions[256] = { /* initializer */ };
    memcpy(mystruct.functions, functions, sizeof(functions));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this routine that calculates the seconds-to-date for a struct tm . On
I have a function that takes pointer to pointer to struct. struct ABC; void
I have a struct like this: class Items { private: struct item { unsigned
Suppose I have a struct called foo_boolean that contains some boolean values: struct foo_boolean
I have a struct that I'd like to export to a file, and then
I have a class that contains some data, and I would like to add
i have a sprite in an array when calling it like this [c1 objectAtIndex:0];
In my C# application, I have a large struct (176 bytes) that is passed
I have a function that takes a struct, and I'm trying to store its
I have a fairly simple const struct in some C code that simply holds

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.