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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:45:35+00:00 2026-05-30T10:45:35+00:00

I think I may be suffering from the dreaded accidental programmer disease, at least

  • 0

I think I may be suffering from the dreaded “accidental programmer” disease, at least when it comes to typedefs and function pointers. So I’ve been experimenting with all kinds of combinations involving these to analyse the results based on all the output I get.

But as I kept on trying different combinations, instead of analyzing the results I’m now just lost in process.

I’m hoping you guys will help me figure out this mess.

First code example

typedef void (print)(void);
void do_something (void) { printf("Hello World\n"); }

print *pr;
pr = &do_something;
pr(); // Hello World

Second code example

typedef void (print)(void);
void do_something (void) { printf("Hello World\n"); }

print *pr;
pr = do_something;
pr(); // Hello World

How do both the above code examples work, it’s as if ‘&’ has no effect on function name

third code example

typedef void (print)(void);
void do_something (void) { printf("Hello World\n"); }

print pr;
pr = do_something; // compile error
pr = &do_something; // compile error
pr();

I was hoping one of the above assignments to work here but damn! I really don’t understand function pointers (and maybe typedef too).

  • 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-30T10:45:36+00:00Added an answer on May 30, 2026 at 10:45 am

    The address of a function name and the plain function name both mean the same thing, so & has no effect on a function name.

    Similarly, when using function pointers, multiple dereferencing isn’t a problem:

    #include <stdio.h>
    typedef void print(void);
    static void dosomething(void) { printf("Hello World\n"); }
    
    int main(void)
    {
        print *f1 = dosomething;
        print *f2 = &dosomething;
        f2();
        (f1)();
        (*f1)();
        (**f2)();
        (***f1)();
        (****f2)();
        (*****f1)();
    }
    

    That compiles cleanly under:

    gcc -O3 -g -Wall -Wextra -Werror -Wmissing-prototypes -Wstrict-prototypes \
        -Wold-style-definition -std=c99 xx.c -o xx
    

    I would not claim that multiple stars is good style; it isn’t. It is ‘odd, and (yes, you may say it) perverse’. One is sufficient (and the one star is mainly for people like me who learned to program in C before the standard said “it is OK to call a function via a pointer without using the (*pointer_to_function)(arg1, arg2) notation; you can just write pointer_to_function(arg1, arg2) if you like”). Yes, it is weird. No, no other type (or class of types) exhibits the same behaviour, thank goodness.

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

Sidebar

Related Questions

I've found what I think may be a bug with Ivar and Objective-C runtime.
You may think this question is like this question asked on StackOverflow earlier. But
I think I may have a misunderstanding of <xsl:variable\> and <xsl:value-of\> so perhaps someone
I think I may have accidently disabled stylecop in my Visual Studio 2008 enviroment.
I think I may be a bit confused on the syntax of the Moq
I think we may have trouble with our existing project. For some reasons we
Do you think it may be OK for a person to have more than
This isn't quite as straight forward as one may think. I'm using a plugin
Hopefully this question isn't as subjective as I think it may be. I have
Sometimes it's difficult to describe some of the things that us programmers may think

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.