23/06/07 12:34:45.81 hQs7a5Jyd.net
>>207
じゃあ、ほい
struct CUE{
int size;
int max;
int inp;
int out;
char buf[1];
};
struct CUE *create_cue(int size, int max)
{
struct CUE *cue =malloc(sizeof(struct CUE)+size*max);
if(cue){
cue->size=size;
cue->max=max;
cue->inp=cue->out=0
}
return cue;
}
int cue_get(struct CUE *cue, void*data)
{
if( cue->inp ==cue->out )
return 0;//buffer empty
memcpy(data,&cue->buf[cue->out* cue->size],cue->size);
if(++cue->out>=cue->max) cue->out=0;
return 1;
}
int cue_add(struct CUE *cue, void*newdata)
{
int index = cue->inp;
if(++index>=cue->max) index=0;
if( index ==cue->out ) return 0;//buffer full
memcpy(&cue->buf[cue->inp* cue->size],newdata,cue->size);
cue->inp=index;
return 1;
}
目をつぶって作ったのでバグがあっても知らない
要するにこういうことでしょ
他の人が言ってるように型チェックがまったく働かないので俺は使いたくない