Sunday, August 2, 2009

Struct timeval continued?

First I need to clarify some things that were pointed out. Yes this is C code and the reason why I was declaring


struct timeval queue[QSIZE]


outside the main function is because other functions need access to it. I tried to use malloc() inside the main function as it was suggested but now I'm getting a "syntax error before token '=' "on this line:





queue = (struct timeval *) malloc(QSIZE * sizeof(struct timeval));





Do I really need to use malloc() to allocate memory. Can the C compiler figure it out since I'm telling it that is an array of type timeval struct?Thanks in advance.

Struct timeval continued?
you don't need malloc - your declaration already allocated enough memory to store QSIZE elements.


Alternatively, you could declare it as


struct timeval *queue;


then you would need to do malloc() yourself.

song downloads

No comments:

Post a Comment