S
S S
Hi
Here is the situation,
I have one line "a.h" as below
extern "C" void afun(int a)
I have "a.cc" as below
#include<iostream>
using namespace std;
extern "C" void afun(int a)
{
cout << "A= " << a;
}
I have "main.cc" as below
#include<iostream>
#include "a.h"
using namespace std;
int main()
{
afun(10);
return 0;
}
Now I compile the a.cc file and create a shared library a.so
g++ -shared -fPIC a.cc -o a.so
Now I compile main.cc using a.h and a.so and create executable a.out
g++ -g a.h main.cc a.so
When I run executable 'a.out', I get output as below
A= 10
which is of course correct.
Now I modify a.h and a.cc with one extra argument as below,
a.h
===
extern "C" void afun(int a, int b = 1);
a.cc
===
#include<iostream>
using namespace std;
extern "C" void afun(int a, int b)
{
cout << "A= " << a << "B= " <<b;
}
Now I again update my a.so with below command
g++ -shared -fPIC a.cc -o a.so
But I do not want to update my a.out, I want new shared file to be
used with old executable 'a.out' and that is the sole purpose of
adding default argument (otherwise non default argument could also be
the choice).
But when I run a.out, I get
A= 10 B= -18776767
which is ofcourse garbage value.
Why default argument is not reflected in shared file and the
executable?
And yes, new argument is surely reflected as seen from output !
Thanks
Here is the situation,
I have one line "a.h" as below
extern "C" void afun(int a)
I have "a.cc" as below
#include<iostream>
using namespace std;
extern "C" void afun(int a)
{
cout << "A= " << a;
}
I have "main.cc" as below
#include<iostream>
#include "a.h"
using namespace std;
int main()
{
afun(10);
return 0;
}
Now I compile the a.cc file and create a shared library a.so
g++ -shared -fPIC a.cc -o a.so
Now I compile main.cc using a.h and a.so and create executable a.out
g++ -g a.h main.cc a.so
When I run executable 'a.out', I get output as below
A= 10
which is of course correct.
Now I modify a.h and a.cc with one extra argument as below,
a.h
===
extern "C" void afun(int a, int b = 1);
a.cc
===
#include<iostream>
using namespace std;
extern "C" void afun(int a, int b)
{
cout << "A= " << a << "B= " <<b;
}
Now I again update my a.so with below command
g++ -shared -fPIC a.cc -o a.so
But I do not want to update my a.out, I want new shared file to be
used with old executable 'a.out' and that is the sole purpose of
adding default argument (otherwise non default argument could also be
the choice).
But when I run a.out, I get
A= 10 B= -18776767
which is ofcourse garbage value.
Why default argument is not reflected in shared file and the
executable?
And yes, new argument is surely reflected as seen from output !
Thanks