Hello,
I am working on upgrading an existent project.
I have a method with this the following prototype:
void f2(struct myStruct **myStructArray )
Now, I need to call a method with the following prototype
whenever f2 is called:
void f1(struct myStruct *myStructElemen t)
Though f2 get an array, in fact it is **always** called with one
element.
This is a working assumption on which I can base my work.
(though in the beginning of this project it was meant to enable
calling this f2 with an array with more than one element).
What I tried is this:
#include <stdio.h>
struct myStruct
{
int val;
};
void f2(struct myStruct **myStructArray )
{
printf("myStruc t->val=%d\n",(*my StructArray)->val );
}
void f1(struct myStruct *myStructElemen t)
{
struct myStruct **myStructArray ;
*myStructArray= myStructElement ;
f2(myStructArra y);
}
int main(int argc, char** argv)
{
struct myStruct *mystruct = (struct
myStruct*)mallo c(sizeof(*mystr uct));
mystruct->val=1;
f1(mystruct);
return 0;
}
Now, when building with -Wall -O2
I get:
main.c: In function ‘f1’:
main.c:19: warning: ‘myStructArray’ is used uninitialized in this
function
(without this flags, compilation completes with no warnings).
How can I avoid this warning messages when building with
-Wall -O2 ? any ideas?
Regards,
Mark
I am working on upgrading an existent project.
I have a method with this the following prototype:
void f2(struct myStruct **myStructArray )
Now, I need to call a method with the following prototype
whenever f2 is called:
void f1(struct myStruct *myStructElemen t)
Though f2 get an array, in fact it is **always** called with one
element.
This is a working assumption on which I can base my work.
(though in the beginning of this project it was meant to enable
calling this f2 with an array with more than one element).
What I tried is this:
#include <stdio.h>
struct myStruct
{
int val;
};
void f2(struct myStruct **myStructArray )
{
printf("myStruc t->val=%d\n",(*my StructArray)->val );
}
void f1(struct myStruct *myStructElemen t)
{
struct myStruct **myStructArray ;
*myStructArray= myStructElement ;
f2(myStructArra y);
}
int main(int argc, char** argv)
{
struct myStruct *mystruct = (struct
myStruct*)mallo c(sizeof(*mystr uct));
mystruct->val=1;
f1(mystruct);
return 0;
}
Now, when building with -Wall -O2
I get:
main.c: In function ‘f1’:
main.c:19: warning: ‘myStructArray’ is used uninitialized in this
function
(without this flags, compilation completes with no warnings).
How can I avoid this warning messages when building with
-Wall -O2 ? any ideas?
Regards,
Mark
Comment