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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:57:16+00:00 2026-06-13T09:57:16+00:00

Here is the content of src1.c: #include <stdio.h> extern int w; //int go(char); //

  • 0

Here is the content of src1.c:

#include <stdio.h>
extern int w;
//int go(char); // no need to declare here. WHY????
  main(){
    char a='f';
    go(a);
    printf("%d\n", w);
}

And here is the content of src2.c:

#include <stdio.h>
int w = 99;
int go(char t){
   printf("%c\n%d\n",t,sizeof(t));
}

Why isn’t it mandatory to declare the go function in src1.c file after compiling it in Linux?

 cc src1.c src2.c; 

Does the compiler put the go function’s definition from src2.c file above the main function’s code so that declaration then would not be required?

In I do it this way:

#include <stdio.h>
int go(char); // need to declare here, because if not, arguments of go will be promoted to intS and they would conflict with char parameters defined in go. Error is droped!
  main(){
    char a='f';
    go(a);
} 
  int go(char t){
   printf("%c\n%d\n",t,sizeof(t));
}

So everyone that says, it is possible to pass whatever number and types of arguments in absence of prototype is wrong. They are promoted to ints in this case, but have to agree with those specified in definition.


I did some tests and found out that even it compiles with no errors it does not work correctly.

src1:

#include <stdio.h>
int go(int t){
    printf("%d\n%d\n",t,sizeof(t));
}

sr2.c:

#include <stdio.h>
int go(int); //if I omit this prototype, program outputs 1 which is far from correct answer :)
main(){ 
    double b=33453.834;
    go(b);
}

So finally the answer could only be undefined behavior.

Thanks Maxim Skurydin

  • 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-13T09:57:17+00:00Added an answer on June 13, 2026 at 9:57 am

    It’s indeed not mandatory to have a prototype for a function before using it, but this is a quirk of the early days of C.

    When there is no prototype present, the compiler cannot check the actual types that are being passed to the function or returned by it, which might be very bad in case of mismatch between the usage and declaration.

    When compiler sees no prototype for go when go(b); is invoked, it assumes it has the following prototype int go(<any number of arguments can be there>). The default argument promotions are performed on the arguments prior to function invocation. Of course, if there is no function go in another translation module, you will get a linker error.

    From c99 standard:

    6.5.2.2 Function calls

    If the expression that denotes the called function has a type that
    does not include a prototype, the integer promotions are performed on
    each argument, and arguments that have type float are promoted to
    double. These are called the default argument promotions. If the
    number of arguments does not equal the number of parameters, the
    behavior is undefined. If the function is defined with a type that
    includes a prototype, and either the prototype ends with an ellipsis
    (, …) or the types of the arguments after promotion are not
    compatible with the types of the parameters, the behavior is
    undefined. If the function is defined with a type that does not
    include a prototype, and the types of the arguments after promotion
    are not compatible with those of the parameters after promotion, the
    behavior is undefined, except for the following cases:

    — one promoted
    type is a signed integer type, the other promoted type is the
    corresponding unsigned integer type, and the value is representable in
    both types;

    — both types are pointers to qualified or unqualified
    versions of a character type or void.

    6.3.1.1 Boolean, characters, and integers

    2/ If an int can represent all values of the original type, the value
    is converted to an int; otherwise, it is converted to an unsigned int.
    These are called the integer promotions.48) All other types are

    update:

    Does compiler put the go function’s definition from src2.c file above
    the main function’s code so that declaration then would not be
    required?

    No, it doesn’t put anything. A cite of the standard above says that no prototype is necessary. Each file is compiled independently so when src1.c is compiled, it doesn’t know anything about src2.c and a go function definition inside.

    So everyone that says, it is posible to pass whatever number and types
    of arguments in absence of prototype is wrong. They are promoted to
    intS in this case, but have to agree with those specified in
    definition.

    It is possible and I’ve faced a couple of obscure bugs after system-wide change that compiled just fine without any warnings for some reason (actually, it’s undefined behavior).
    Again, since each *.c file is compiled independently, there is now way it can check the number of arguments and their types of go function defined in another translation unit. If the function takes more arguments that you have provided, the “unused” arguments will be filled with some random data. You should keep in mind, that if arguments don’t match – it’s undefined behavior, which means that anything can happen.

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

Sidebar

Related Questions

the url format is: domain/startValue/endValue/content here, startValue and endValue take either int or float
I have this string <p><img src=http://www.foo.com/bar.jpg></p><p>other content here</p> I need to extract the src
I have created Raphael content here .. http://jsfiddle.net/ryWH3/76/ Now I need to move the
Need a bit of PHP help here, the included content is appearing as '1'
I want to be able to have default text like Enter content here... appear
I have the following structure: <div class=parent> <div id=child1>Content here</div> <div class=child2>Content here</div> </div>
Here is the content of file User.php <?php class My_Controller_Plugin_User extends Zend_Controller_Plugin_Abstract { public
I have some content sliding here. http://www.smallsharptools.com/downloads/jQuery/Slider/slider.html The HTML structure is simple. There is
I'm making a form with a choice list. Here's the content of my FormType
I have some HTML that looks like this: <div class=product> Content In Here <div

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.