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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:39:13+00:00 2026-05-18T01:39:13+00:00

As I asked and answered in this post . I have the following example

  • 0

As I asked and answered in this post. I have the following example code.

#include <stdio.h>

char foo()    { return 'a'; }
char bar()    { return 'b'; }
char blurga() { return 'c'; }
char bletch() { return 'd'; }

char (*gfunclist[])() = {foo, bar, blurga, bletch};

char (*(*x())[])()
{
  static char (*funclist[4])() = {foo, bar, blurga, bletch};
  return funclist;
}

int main() 
{
  printf("%c\n",gfunclist[0]());

  char (**fs)();
  fs = x();
  printf("%c\n",fs[1]()); 
}

My questions are

  • Why the
    return funclist (with "warning: return from incompatible pointer type")

    and

    return &funclist

    both works?

  • I get warning at the line 21 (fs = x();) of
    warning: assignment from incompatible pointer type

    . How to remove this warning?

ADDED

With AndreyT’s help. I could get the following code that doesn’t have the warnings.

#include <stdio.h>

char foo()    { return 'a'; }
char bar()    { return 'b'; }
char blurga() { return 'c'; }
char bletch() { return 'd'; }

char (*gfunclist[])() = {foo, bar, blurga, bletch};

char (*(*x())[])()
{
  static char (*funclist[4])() = {foo, bar, blurga, bletch};
  return &funclist;
}

int main() 
{
  printf("%c\n",gfunclist[0]());

  char (*(*fs)[4])();
  fs = x();
  printf("%c\n",(*fs)[1]()); 
}

And this is less messy code with the help from peoro.

typedef char (*funptr)();

funptr gfunclist[] = {foo, bar, blurga, bletch};

funptr* x()
{
  static funptr funclist[4] = {foo, bar, blurga, bletch};
  return funclist;
}

int main() 
{
  printf("%c\n",gfunclist[0]());

  funptr *fs;
  fs = x();
  printf("%c\n",fs[1]()); 
}
  • 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-18T01:39:14+00:00Added an answer on May 18, 2026 at 1:39 am

    You have to decide whether you are using C or C++. These languages are significantly different in their treatment of the situations like yours.

    In C++ a “pointer to an [] array” (i.e an array of unspecificed size) is a completely different type from a “pointer to an [N] array” (i.e. an array of specified size). This immediately means that your code has no chance to compile as C++ code. It is not a “warning”, it is an error. If you want your code to compile as C++, you need to specfiy the exact array size in the function return type

    char (*(*x())[4])() // <- see the explicit 4 here?
    {
      static char (*funclist[4])() = {foo, bar, blurga, bletch};
      return &funclist;
    }
    

    And, of course, you have to return &funclist, since you are declaring your function as returning a pointer to an array.

    In main declaring the receiving pointer as char (**fs)() makes no sense whatsoever. The function is returning a pointer to an array, not a pointer to a pointer. You need to declare your fs as

    char (*(*fs)[4])(); // <- pointer to an array
    

    i.e. as having pointer-to-array type (note the similarity to the function declaration). And in order to call the function through such a pointer you have to do

    printf("%c\n", (*fs)[1]()); 
    

    In C language the explicit array size in the pointer-to-array declarations can be omitted, since in C “pointer to an [] array” type is compatible with “pointer to an [N] array” type, but the other points still stand. However, even in C it might make more sense to specify that size explicitly.


    Alternatively, you can stop using pointer-to-array type and instead use pointer-to-pointer type. In that case your function should be defined as follows

    char (**x())()
    {
      static char (*funclist[4])() = {foo, bar, blurga, bletch};
      return funclist; // <- no `&` here
    }
    

    and in main you’ll work with it as follows

    char (**fs)();
    fs = x();
    printf("%c\n", fs[1]()); 
    

    Note, that this main is the same as what you had in your original post. In other words, your original code is a bizarre fusion of two different absolutely incompatible techniques. You have to decide which one you want to use and stick to it.

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

Sidebar

Related Questions

As asked and answered in this post , I need to replace '[' with
As is asked and answered in this post , one can use SyntaxHighlighter for
This question was asked but was not answered. I have contact form and I
this must have been asked and answered but couldn't find an answer. What I'd
Question: I have a question that is apparently not answered by this already-asked Bash
I have no doubt this has been asked and answered here a dozen times,
I know that this question must have been asked and answered a million times,
If this has already been asked and answered, please point me to the existing
Edit : This question has already been asked and answered, and I apparently am
It seems this type of question has been asked and answered a number of

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.