L
luserXtrog
Can anyone shed light upon this warning. From the line
number it refers to the anonymous union, but I don't
understand what the compiler's griping about.
193(1)09:30 PM:~ 0> gcc -std=c99 -o list list.c
list.c:12: warning: declaration does not declare anything
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int error(char *s){ fprintf(stderr, "%s\n", s); exit(EXIT_FAILURE); }
struct sexpr {
bool atom;
union {
int cari;
struct sexpr *carl;
};
struct sexpr *cdr;
};
struct list {
int *car;
struct list *cdr;
};
bool init() {
struct list *lp, *h;
(lp=malloc(sizeof*lp)) || error("poof!");
h=lp;
for(int *i = (int[]){ 42, 69, 613, 0 }; *i; i++) {
lp->car = i;
(lp->cdr=malloc(sizeof*lp)) || error("poof!");
lp = lp->cdr;
*lp = (struct list){ NULL, NULL };
}
return true;
}
struct list *read(FILE *f) {
struct list *lp;
int c;
(lp=malloc(sizeof*lp)) || error("poof!");
while( EOF!= (c=fgetc(stdin)) ) {
switch(c) {
case '(': lp->car = 0;
lp->cdr = read(f);
break;
case ')': return NULL;
default:
(lp->car=malloc(sizeof*lp)) || error("poof!");
*lp->car = c;
}
}
return lp;
}
struct list *eval(struct list *lp) {
return lp;
}
bool print(FILE *f, struct list *lp) {
if (lp) {
fprintf(f, "%d\n", lp->car);
print(f,lp->cdr);
return true;
} else {
return false;
}
}
bool run() {
while (print(stdout,eval(read(stdin)))) ;
return true;
}
int main() {
return init()&&run()?0:EXIT_FAILURE;
}
/*eof*/
number it refers to the anonymous union, but I don't
understand what the compiler's griping about.
193(1)09:30 PM:~ 0> gcc -std=c99 -o list list.c
list.c:12: warning: declaration does not declare anything
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int error(char *s){ fprintf(stderr, "%s\n", s); exit(EXIT_FAILURE); }
struct sexpr {
bool atom;
union {
int cari;
struct sexpr *carl;
};
struct sexpr *cdr;
};
struct list {
int *car;
struct list *cdr;
};
bool init() {
struct list *lp, *h;
(lp=malloc(sizeof*lp)) || error("poof!");
h=lp;
for(int *i = (int[]){ 42, 69, 613, 0 }; *i; i++) {
lp->car = i;
(lp->cdr=malloc(sizeof*lp)) || error("poof!");
lp = lp->cdr;
*lp = (struct list){ NULL, NULL };
}
return true;
}
struct list *read(FILE *f) {
struct list *lp;
int c;
(lp=malloc(sizeof*lp)) || error("poof!");
while( EOF!= (c=fgetc(stdin)) ) {
switch(c) {
case '(': lp->car = 0;
lp->cdr = read(f);
break;
case ')': return NULL;
default:
(lp->car=malloc(sizeof*lp)) || error("poof!");
*lp->car = c;
}
}
return lp;
}
struct list *eval(struct list *lp) {
return lp;
}
bool print(FILE *f, struct list *lp) {
if (lp) {
fprintf(f, "%d\n", lp->car);
print(f,lp->cdr);
return true;
} else {
return false;
}
}
bool run() {
while (print(stdout,eval(read(stdin)))) ;
return true;
}
int main() {
return init()&&run()?0:EXIT_FAILURE;
}
/*eof*/