Z
Zach
This runs with the expected results, but I would like to understand
this warning and eliminate it. If I change lines 38 and 39 to be:
test.prev = *a;
test.next = *b;
Then it compiles with no warnings but it prints out garbage values for
a and b after I call get_token().
Zach
chaos@cobalt:~/myprojects/netrek-log-parser$ gcc -o ll ll.c
ll.c: In function ‘get_token’:
ll.c:38: warning: assignment makes pointer from integer without a cast
ll.c:39: warning: assignment makes pointer from integer without a cast
chaos@cobalt:~/myprojects/netrek-log-parser$ ./ll
Test 1 2
Test 1 2
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char *data;
int *prev, *next;
}node;
node test;
node get_token(char *, int *, int *);
int main(void)
{
char *p = "Test";
int *a = malloc(sizeof(int));
int *b = malloc(sizeof(int));
*a = 1;
*b = 2;
printf("%s %d %d\n",p,*a,*b);
get_token(p,a,b);
printf("%s %d %d\n",test.data,test.prev,test.next);
return EXIT_SUCCESS;
}
node get_token(char *p, int *a, int *b)
{
test.data = p;
test.prev = *a;
test.next = *b;
free(a);
free(b);
return test;
}
this warning and eliminate it. If I change lines 38 and 39 to be:
test.prev = *a;
test.next = *b;
Then it compiles with no warnings but it prints out garbage values for
a and b after I call get_token().
Zach
chaos@cobalt:~/myprojects/netrek-log-parser$ gcc -o ll ll.c
ll.c: In function ‘get_token’:
ll.c:38: warning: assignment makes pointer from integer without a cast
ll.c:39: warning: assignment makes pointer from integer without a cast
chaos@cobalt:~/myprojects/netrek-log-parser$ ./ll
Test 1 2
Test 1 2
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char *data;
int *prev, *next;
}node;
node test;
node get_token(char *, int *, int *);
int main(void)
{
char *p = "Test";
int *a = malloc(sizeof(int));
int *b = malloc(sizeof(int));
*a = 1;
*b = 2;
printf("%s %d %d\n",p,*a,*b);
get_token(p,a,b);
printf("%s %d %d\n",test.data,test.prev,test.next);
return EXIT_SUCCESS;
}
node get_token(char *p, int *a, int *b)
{
test.data = p;
test.prev = *a;
test.next = *b;
free(a);
free(b);
return test;
}