开发者

Still problems with LLIST *mylist[x]

开发者 https://www.devze.com 2022-12-17 16:50 出处:网络
So I have... int x; LLIST *mylist[x]; x =10; bzero(mylist, sizeof(LLIST *)*x); this does not seem to be a valid solution..

So I have...

int x; LLIST *mylist[x]; x =10; bzero(mylist, sizeof(LLIST *)*x);

this does not seem to be a valid solution..

I did add the开发者_如何学Python -std=c99 to my make file, just this alone did not work which is why emil suggested the above approach, because I had originally:

int x=10;

LLIST *mylist[x] = {NULL};

My make file looks like this:

CC=gcc CFLAGS=-Wall -g -std=c99

LIBS=-lreadline -lm OBJS=llist.o myprogram.o INCLUDES=llist.h

all: $(OBJS) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o myprogram

.c.o: $.h $(INCLUDES) $(CC) $(CFLAGS) -c $.c

clean: rm -f *.o myprogram


This code:

int x; 
LLIST *mylist[x];
x = 10;
bzero(mylist, sizeof(LLIST *)*y);

has two problems:

  1. You are using x line 2 before giving it a value on line 3.
  2. You are using variable y in line 4.

I recommend tow changes. First combine the definition and initialization of x into a single line. Second, use sizeof(VAR) and rather then recomputing the size based on the type:

int x = 10;
LLIST *mylist[x];
bzero(mylist, sizeof(mylist));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号