Getting these warnings when I used the below code snippet. Can any one help me to resolve?
new_str.c: In function ‘main’:
new_str.c:39:25: warning: passing argument 2 of ‘send_to_host’ from incompatible pointer type [-Wincompatible-pointer-types]
39 | send_to_host(MACRO,ram->s1);
| ~~~^~~~
| |
| stats_t * {aka struct stats_s *}
new_str.c:28:34: note: expected ‘int *’ but argument is of type ‘stats_t *’ {aka ‘struct stats_s *’}
28 | void send_to_host(int macro,int *data)
| ~~~~~^~~~
new_str.c:42:25: warning: passing argument 2 of ‘send_to_host’ from incompatible pointer type [-Wincompatible-pointer-types]
42 | send_to_host(MACRO,ram->a1);
| ~~~^~~~
| |
| abc_t * {aka struct abc_s *}
new_str.c:28:34: note: expected ‘int *’ but argument is of type ‘abc_t *’ {aka ‘struct abc_s *’}
28 | void send_to_host(int macro,int *data)***
#include <stdio.h>
#include <stdlib.h>
#define MACRO 12
typedef struct stats_s{
int tx;
int rx;
int err;
}stats_t;
typedef struct abc_s{
int a;
int b;
int c;
}abc_t;
typedef struct ram_s{
int dummy;
int dam;
stats_t *s1;
abc_t *a1;
}ram_t;
ram_t ram1;
void send_to_host(int macro,int *data) // 28
{
printf("function called\n");
}
void main(){
ram_t *ram;
ram = &ram1;
send_to_host(MACRO,ram->s1); // 39
send_to_host(MACRO,ram->a1); // 42
}
You need to send pointer to int (reference to int type struct member) not dereference pointer to struct (this pointer is not related to the type of the parameter).
send_to_host(MACRO,&ram -> s1 -> tx); // 39
send_to_host(MACRO,&ram -> a1 -> a); // 42
Below code is not needed at all.
ram_t *ram;
ram = &ram1;
simply:
send_to_host(MACRO,&ram1.s1 -> tx); // 39
send_to_host(MACRO,&ram1.a1 -> a); // 42
The main
function signature has to be:
int main(void){
/* ... */
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.