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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:25:49+00:00 2026-05-20T07:25:49+00:00

Let’s say I only want to expose a function from one of my files

  • 0

Let’s say I only want to expose a function from one of my files by passing out a function pointer to that function. Is it safe to declare that function as static? Are compilers allowed to do any judo that would invalidate my function pointer, or make it meaningless outside the context of that file, since the function is declared as specific to that file?

Not my code, but a (silly) example of what I mean:

void    static   cool_function(void);
void    extern (*cool_function_ptr)(void); // Actually, I’m not sure of where the `extern` goes in a function-
                                           // pointer declaration. Damn you, confusing function-pointer syntax!

Given that code (or the syntactically correct approximation thereof), would it be illegal to access cool_function_ptr from another file?

  • 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-20T07:25:49+00:00Added an answer on May 20, 2026 at 7:25 am

    It is completely safe to do so, and often useful. The same goes for static variables and data pointers. If the compiler wants to do any fancy optimizations (like nonstandard calling conventions, inlining, refactoring, etc.) that could interfere with the ability to call the function through a function pointer from a different translation unit, it’s the compiler’s responsibility to either determine that the address of the function is never taken, or to generate multiple versions of the code, one of which is safe to be called from outside with the standard calling convention.

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

Sidebar

Related Questions

I only want log4net to keep let's say 10 days-worth of log files as
Let's say I have a block of code that is copied from one file
Let's say we want to do some substitutions only between some patterns, let them
Let's say you have a profile page that can only be accessed by the
Let's say I have a Type II SCD database, that is basically append only.
I would like to store only .txt filenames from a specific dir (let's say:
Let say, that i have defined the same function for windows and mac, with
Let's say I need to display a list of customers, but only want to
Let's say I have a rails app with content that's read-only to the public,
Let's say I make a program. I only want this program to run on

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.