M
mohan
Hi All,
How to implement virtual concept in c.
TIA
Mohan
How to implement virtual concept in c.
TIA
Mohan
mohan said:How to implement virtual concept in c.
Hi All,
How to implement virtual concept in c.
TIA
Mohan
mohan said:Hi All,
How to implement virtual concept in c.
mohan said:> Well I wanted to achieve dynamic polymorphism in c . Ie calling
> function dynamically depending upon the type
Chuck said:*** top-posting corrected ***
Don't top-post. Your answer belongs after, or intermixed with, the
snipped quoted material to which you reply.
C doesn't allow this. Actually, neither does C++, it fakes it by
modifying all function names. That is why linking from C++ to normal
languages is virtually impossible, and why the 'extern "C"' directive is
available in C++.
mohan said:Well I wanted to achieve dynamic polymorphism in c .
Why?
Ie calling function dynamically depending upon the type
Here is a simple example of how you can achieve polymorphisms. ...
#include <stdio.h>
#include <stdlib.h>
void intMyFunc(int ii)
{
printf("int parameter virtual function (%d)\n",ii);
}
enum {
VINT,
VSTRING
};
int main(int argc,char **argv)
{
int ii = 456;
myFunc(VINT,&ii);
}
void myFunc(int varg,void *arg)
{
union
{
void *vv;
int *ii;
} virt_arg;
virt_arg.vv = arg;
switch(varg)
{
case VINT : intMyFunc(*virt_arg.ii); break;
Chris said:Joseph Dionne said:Here is a simple example of how you can achieve polymorphisms. ...
This code will not work on the Data General Eclipse, because:
[Snippage below no longer marked; I retained only the amount of
code needed to show where it breaks. Note that this removed some
error checking. I also re-ordered the code so that the problem
will be more obvious.]
#include <stdio.h>
#include <stdlib.h>
void intMyFunc(int ii)
{
printf("int parameter virtual function (%d)\n",ii);
}
enum {
VINT,
VSTRING
};
int main(int argc,char **argv)
{
int ii = 456;
myFunc(VINT,&ii);
Hi All,
How to implement virtual concept in c.
TIA
Mohan
Well I wanted to achieve dynamic polymorphism in c . Ie calling function
dynamically
depending upon the type
Mohan
I don't know the architecture of a Data General Eclipse, however code "like"
this is running on DG boxes now.
I have just tested the module posted on AIX RISK, v4 and v5, Sun SPARC v6, 7,
and 9 without failure.
Unfortunately, I would need to buy time on my
development DG boxes, which I have no intention on doing to validate
your claims.
My reply was to provide a hint as to how one could "achieve dynamic
polymorphism."
You have provided a solution for a specific platform
which the OP may or may not be using, so thank you for your efforts.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.