Momment Member
Posts : 19 Join date : 2011-03-09
| Subject: insane c error on seemingly correct code Sun May 15, 2011 2:07 am | |
| I am working on a sort function and and after getting the strangest error visual studios seems think all local symbols (including func args) are undeclared identifiers. This has been stumping me for a few days now. So here I submit to the higher power of the internet to figure out what in the world is going on. I do realize that this code may be hard to read as I wrote it with minimal compiled size in mind. - Code:
-
struct list_entry { struct rt_info *next; struct rt_info *prev; };
struct rt_info { int value; struct list_entry list[SCHED_LISTS]; }; int compare(struct rt_info *t1, struct rt_info *t2, int key, int before) { if(before) return t1->value > t2->value; else return t1->value < t2->value; } void link_nodes(struct rt_info * a, struct rt_info * b, const int i) { b->list[i].prev=a; a->list[i].next=b; }
struct rt_info * merge(struct rt_info * l[2],int i,int key,int before){ struct rt_info * cur; struct rt_info * e[2]; struct rt_info * tmp; for(int j=0;j<2;++i){ tmp=e[j]=l[j]->list[i].prev; tmp->list[i].next=NULL; } int x=1-compare(l[0],l[1],key, before); cur=l[x]; while(1){ while (compare(l[x],l[1-x],key,before)){ tmp=l[x]; l[x]=tmp->list[i].next; if(l[x]==NULL){ link_nodes(e[x],l[1-x],i); cur->list[i].prev=e[1-x]; return cur; } } link_nodes(tmp,l[1-x],i); x=1-x; } } void mergesort(struct rt_info * start, struct rt_info * end, int i, int key, int before) { struct rt_info * cur=start->list[i].next; if(cur==end) return; struct rt_info * stk=start; struct rt_info * nxt, * tmp; unsigned ctrl=-1; goto in; while(nxt!=end){ cur->list[i].prev->list[i].next=stk; stk=cur; cur=nxt; in: tmp=cur->list[i].next; if(tmp==end) tmp=cur; nxt=tmp->list[i].next; link_nodes(tmp,cur,i); cur = compare(cur,tmp,key,before)?cur:tmp; --ctrl; clean_up: for(int it=ctrl;it&0x1;it>>=1){ tmp=stk; stk=stk->list[i].prev->list[i].next; rt_info*arg[2]={cur,tmp}; cur=merge(arg,i,key,before); } } if(stk!=start){ ctrl=~ctrl; ctrl-=((ctrl>>1)&033333333333)-((ctrl>>2)&011111111111); ctrl=0x1<<((ctrl+(ctrl>>3))&030707070707)%63; goto clean_up; } end->list[i].prev=cur->list[i].prev; link_nodes(start,cur,i); }
|
|
Carbon Member
Posts : 12 Join date : 2011-03-09
| Subject: Re: insane c error on seemingly correct code Sun May 15, 2011 2:08 am | |
| Which section errors? What are the errors? It would take me too long to go through the code checking all the logic/variables, and I don't have visual studio. |
|
Understand Member
Posts : 21 Join date : 2011-03-09
| Subject: Re: insane c error on seemingly correct code Sun May 15, 2011 2:08 am | |
| Yes please give us the errors it is reporting. If you are missing a semicolon some place that will cause errors similar to what you described, or if you have a type, variable or constant that you use but isn't defined.
Also as an aside, using gotos is strongly discouraged by most professional programmers it creates spaghetti code that is hard to debug. There is almost always a slightly different way to write it so you don't need to the goto. |
|
Momment Member
Posts : 19 Join date : 2011-03-09
| Subject: Re: insane c error on seemingly correct code Sun May 15, 2011 2:09 am | |
| It only errors with the goto commands and labels. comment them out and the code compiles fine. yes there is a way to write this with out goto's it is after all a merge sort but not with out making output code size larger which in this case is critical as this is code for a kernel and must assume cache cold execution. |
|
Sponsored content
| Subject: Re: insane c error on seemingly correct code | |
| |
|