top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

If I have changed the no of parameter at one place where the function is being called.

+7 votes
389 views

If I have changed the no of parameter at some place where the function is being called. How can I be assured that no place is remain. Because build is successful, I cant not declare in header file because it is already extern in many files.

Brief example is given below.

/* main.c */
#include <stdio.h>
extern fun (int i ,int j);
int main()
{
printf("\n In main \n");
fun(1,3);
return 0;
}
======================================================
/* fun.c */
#include<stdio.h>

int fun(int in)
{
int local1 = in;
int local2 = *(&in +1);
printf("\nlocal1 = %d\tlocal2 = %d\n",local1, local2);
return in;
}
posted Oct 14, 2013 by Vikas Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

I think this should give a linker error.
It is better programming practice to include the extern defination in a .h file rather than including in all the required .c files.so any change in .h file will make the .c files including this .h be automatically recompiled.

answer Oct 14, 2013 by Sony Mohanty
Initially function was static then someone done it extern and every one started it using extern. Now product has thousands of files and function  is extern in a lot of places. So i faced this problem. Product build is successful :). No compile or linking error.
It seems like function overloading in C :)
Even I have tried there is no linking error.
Similar Questions
+3 votes
#include<stdio.h>
#include<string.h>

int main()
{
    char ptr[]= {'a','b','c','0','e'};
    char str[]= "abc0e";
    printf("\nptr = %s\t len = %d\n",ptr, strlen(ptr));
    printf("\nstr = %s\t len = %d\n",str, strlen(str));
    return 0;
}

Output : ptr = abc0e len = 6
str = abc0e len = 5

Why the length for ptr is 6 ? Can someone please explain it ?

+3 votes

A list contains a set of numbers, one number presents once and other numbers present even no. of times. Find out the number that occurs once in the list.

+2 votes

How many parameters can we pass as argument in function? Is there any limit ?
If yes , Please explain the reason.

+1 vote

I have written a simple program and stored it with .c file,
When i compiled it with g++ it is getting compiled and giving the proper output when i run that,
but when i compile the same using gcc then it is throwing error.

Below is the sample .c file
#include<stdio.h>
struct A{
        private:
        int a;
        public:
        int sum(){
        a=10;
        }
        void print()
        {
        printf("%d\n",a);
        }
        A()
        {
                printf("Constructor\n");
        }
        A(int b)
        {
                printf("Copy Constructor\n");
        }
        ~A()
        {
                printf("Destructor\n");
        }
};
main()
{
        struct A a(10);
        a.sum();
        a.print();
}
...