Moved to C++ programming forum.
Printable View
Moved to C++ programming forum.
>> i am trying to write one Generic function
Why are you trying to do this? At this point, we understand "what" you are trying to solve, but not "why".
Why are you locked in on implementing "one Generic function"? It's very likely that there are better ways to solve the "root" problem.
gg
Thank you,
for Reply , but i want to implement this in pure c only,
uding void pointers any help in this direction.
>> i want to implement this in pure c only
Can't be done in standard C.
gg
O_o
Are you trying to write your software so that it's easy to exploit?
Soma
Hello experts,
i dont know why this post is trasfered to c++ forum,
any how i am trying to do some thing like this,
is it possible to use the call by reference for more than 3 levels for ex:
in this way at last in my main method i should get the result both as 10 , even though this is a simple example can be done in two steps only but for some part of my projec i require this type of flow so how to achieve this please help me. how to pass by reference for more than one time.Code:int main()
{
int a=0,b=10;
fun_call(&a,&b);
printf("\n a=%d b=%d",a,b);//i want the output as a=10 b=10
return 0;
}
void fun_call( int *a,int *b)
{
int m=a;
int n=b;
fun_transver(&m,&n);
}
void fun_transver(int *m,int *n)
{
m=n;
}
You have explained perfectly WHAT you want to do, but not why.
The only way you can pass arguments to a function and not know until you get to the function, what those arguments represent, would be by passing another pass a "type" information with the argument.
C is not a particularly good language for this purpose.
--
Mats
The example code seems to be a completely different problem. Sure you can pass the pointers on as many times you like:
Code:void fun_call( int *a,int *b)
{
/*
int* m=a;
int* n=b;
fun_transver(m, n);
*/
fun_transver(a, b);
}
Dear experts,
as i said i require this piece mainly for some other part of my project,
may be my syntax may be wrong,
please tell me how to pass by reference for more than one level so at last i should get the value in main, as required,
i want at last a and b as 10 what is the correct way or syntax i am asking thatCode:int main()
{
int a=0,b=20;
call_fun1(....)
print("\n a=%d b=%d",a,b);//at last i want a=10 b=10
}
call_fun1(int *, int *)
{
call_fun2(...)
}
call_fun2(int *,int *)
{
a=b;
}
any help in this regard is favourable.
ggCode:#include <stdio.h>
void call_fun1(int *pa, int *pb);
void call_fun2(int *pa, int *pb);
int main()
{
int a=0, b=20;
call_fun1(&a, &b);
printf("a=%d, b=%d\n", a, b);
return 0;
}
void call_fun1(int *pa, int *pb)
{
call_fun2(pa, pb);
}
void call_fun2(int *pa, int *pb)
{
*pa = *pb = 10;
}
Thank you codeplug,
really u gave the correct syntax even though the example was simple,
but it solved my big problem i was able to modify lot of things thanks a lot again.
again what to do if one of the variable is a pointer this actually i want to ask if
void *a=0, b=20;
how to achieve the same result, how to convert from void * to int and vice versa,
what is the exact syntax in this case.
http://www.amazon.com/Pointers-C-Ken.../dp/0673999866Code:#include <stdio.h>
void call_fun1(void *pa, void *pb);
int main()
{
int a=0, b=20;
call_fun1(&a, &b);
printf("a=%d, b=%d\n", a, b);
return 0;
}
void call_fun1(void *pa, void *pb)
{
*((int*)pa) = 10;
*((int*)pb) = 10;
}
gg