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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:17:10+00:00 2026-06-05T01:17:10+00:00

My question does not link to a direct example, but is more of a

  • 0

My question does not link to a direct example, but is more of a question as a whole. When I was coding with C++, I found (after looking through some threads) that in order to use functions from different files that are in the same project, I would either need a header file. So, for example, if I have the main function in a file called “main.cpp” and I wanted to use a function, “prob1()” in another file called “problem1.cpp”, I would need to use a header file.

What is confusing me is why I do not have to worry about this for programming in C? When I was programming in C, in order to use functions from different files, I could call the function directly.

Any help/explanation is appreciated. Thanks!

  • 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-06-05T01:17:12+00:00Added an answer on June 5, 2026 at 1:17 am

    Your C compiler can implicitly declare the function, but you should be doing so yourself. If you turn up the warnings, you’ll see something like:

    file1.c: warning: implicit declaration of function ‘func_from_f2’
    

    When file1.c is being compiled, this implicit declaration will be used to create an object file and then when linking you have to just hope that the function actually does exist and the declaration is correct so that the object files can be linked together successfully.

    If not, the linker will give you an error somewhere along the lines of:

    undefined reference to `func_from_f2'
    

    You also don’t necessarily need a header file, you can simply include the declaration/prototype of the function in your source file (the #include directive essentially does this for you). ie. the below will work fine without warnings:

    file1.c

    void func_from_f2(void);
    
    int main(void)
    {
       func_from_f2();
    
       return 0;
    }
    

    file2.c

    #include <stdio.h>
    
    void func_from_f2(void)
    {
       puts("hello");
    }
    

    However, it’s usually best practice that you do use a header file:

    file1.c

    #include "file2.h"
    
    int main(void)
    {
       func_from_f2();
    
       return 0;
    }
    

    file2.h

    #ifndef FILE2_H
    #define FILE2_H
    
    void func_from_f2(void);
    
    #endif
    

    file2.c

    #include <stdio.h>
    #include "file2.h"
    
    void func_from_f2(void)
    {
       puts("hello");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question does not refer to some Vim-mode in Emacs, but to Vim inside
I read this question but the answer does not perform a refactoring of the
I've spotted this question: Does Microsoft SkyDrive have an API? But not having an
Here is a source viewer for fadeIn() but it does not link out to
Is it possible (for example with C++, but it does not really matter) to
(This question does not rely on a specific IoC framework, so the interfaces and
Ok, question does not really make sense. Here is the situation. I have legacy
First, let me state that this is a programming question (and thus does not
The manual does not answer this question : it says the name of the
This question is related to: Windows authentication does not work I am developing a

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.