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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:54:51+00:00 2026-05-26T09:54:51+00:00

The compiler will always whine when I have mixed public with static prototypes in

  • 0

The compiler will always whine when I have mixed public with static prototypes in a header file.

Say I have header main.h with a static prototype for function a and a normal prototype for function b. Then I want to #include the header in two .c files, namely main.c and other.c. In main.c I need an include as I call the function before any prototype.

main.h:

static int a(void);
int b(void);

main.c:

#include "main.h"
void main(){
  a();
}

static int a(void){
  /* do stuff */  
}

int b(void){  
  /* do stuff */  
}

other.c:

#include "main.h"
b();

What’s the best practice for this than the obvious solution of splitting the header file into a seperate header exclusively for static prototypes and one for public ones?

  • 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-26T09:54:52+00:00Added an answer on May 26, 2026 at 9:54 am

    You don’t put declarations of static functions in header files. Since they are local to the .c file that defines them, it doesn’t make sense to export them from a header file.

    There are two things you can do:

    1. Define the function before it is called in the c file (move definition of a() above main).
    2. Declare static function at the top of the C file (this is my personal choice). In your case, you move the declaration of a() to the top of main.c.

    If the function is going to be used in multiple translation units, then you can define the static function in the header file. It could usefully be inline instead of static assuming you have a grown-up compiler that supports C99.

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

Sidebar

Related Questions

Okay here's the program I have typed up(stdio.h is included also): /* function main
I have searched and have been unable to verify how the GCC compiler will
Based on this discussion, I was wondering if a function scope static variable always
I know that the compiler will sometimes initialize memory with certain patterns such as
I learned that compiler will expand macros while compiling. Templates are also expanded at
According to here , the C compiler will pad out values when writing a
C# 3.0 introduced the var keyword. And when compiled, the compiler will insert the
As expected, the compiler (VisualStudio 2008) will give a warning warning C4715: 'doSomethingWith' :
I'm not sure, will the visual c ++ compiler express edition work for compiling
(1). When using C++ template, is it correct that the compiler (e.g. g++) will

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.