ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, i'm wanting to be able to pass any type of variable to a function (penultimately it's a wrapper for fwrite). I'm trying the void type, but am having trouble finding reference to this usage.
I keep changing and trying different ways, but here's an example:
In your test function, you take a pointer, but then you cast the value of the pointer (i.e. the memory address of the pointer) to an int and print that. You need to de-reference your pointer before you print it:
Code:
void test(const void *i)
{
int *j = (int*)i;
printf("i contents: %d \n", *j);
}
/* OR try it all in one go:
void test(const void *i)
{
printf("i contents: %d \n", *((int*)i));
}
*/
I'm still getting same error...
I'll now look into compiler because i've had some other weird results today! (gcc version 4.1.2 20070502 (Red Hat 4.1.2-12))
Paste your code, preferably a minimal version which is just enough to duplicate your error. Also paste the command you use to compile/link the program.
Aha I see. The functions test1 and test2 are defined as returning nothing - void. In the context of a return value to a function this means "no value is returned". Yet you try to assign the return value to the variable iret, which is an int. This is the source of the error.
Either you need to change the return type of the functions to int (and return something), or get rid of these assignments.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.