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

The Archive Base Latest Questions

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

I came across the following difference related to function definition/declaration between C and C++.

  • 0

I came across the following difference related to function definition/declaration between C and C++.

In C++ if I call a function before declaring and defining it,I get the error message ‘function name is invalid identifier’ which is fine for me as it sounds reasonable.

In C with Visual Studio compiler when I compiled the following program I get the error message:

error C2371: 'fun' : redefinition; different basic types

and in gcc-4.3.4 it executed successfully with just this warning:

warning: conflicting types for ‘fun’

Here goes the program:

#include <stdio.h>
int main(){
    fun();
    return 0;
}
void fun(){
    printf("It is fun");
}

So is it fine in C to just call a function and later bother about defining it?! And why the compilers behave differently?

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

    When you call the function without a prototype in C89 (disclaimer: I don’t know about C99), you are implicitly declaring it as

    int fun();

    Note that in C, other than in C++, the empty parantheses just mean that you haven’t specified what arguments it takes, not that it takes zero arguments.

    When you redeclare the function as returning void, you get the warning, but no error. If you return something non-trivial (structs, floats, …) instead of void or if you try to use the int result of the function, then you might be in deep trouble at runtime.

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

Sidebar

Related Questions

Recently in a previous project I came across a peculiar difference between VB.NET and
I'm actively learning javascript, and I came across the following statement: Object.prototype.toString.call([]); And I
I came across the following pattern when looking through the SlickGrid source code: (function
I came across a difference in speed using the following two structs: public struct
I came across following code function currentSlideFromParams() { var result; if (result = window.location.hash.match(/#([0-9]+)/))
I came across the following markup in a JSP file in a legacy app
I came across the following expression in someone else's code. I think it's terrible
I came across the following regular expression below on one of my code, anyone
I came across the following code that compiles fine (using Visual Studio 2005): SomeObject
I came across the following weird chunk of code.Imagine you have the following typedef:

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.