Author |
Message |
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
|
Back to top |
|
|
Arnk Kilo Dylie Seasoned Helper
Age:36 Gender: Joined: Jul 14 2006 Posts: 108 Offline
|
Posted: Wed Nov 03, 2010 9:25 pm Post subject: |
|
|
|
|
FOR_EACH is designed to be safe for removing the element you're working with. That's why it's not a simple link=head;link;link=link->next.
Make sure you're locking properly with all linked lists or other complicated structures. |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Thu Nov 04, 2010 12:34 am Post subject: |
|
|
|
|
Alright, thanks...
I fixed my crash now... not sure exactly what it was, but I fixed a lot of possible usage of obsolete pointers and such |
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 09, 2011 2:16 am Post subject: |
|
|
|
|
this might be late, but i also ran into this awhile ago
personally i find its easier to delete the link im working with instead of jumping through extra hoops not to, but for a long time i was using the following:
#define FOR_EACH_LINK(x) Link *l; for(l=LLGetHead(&(x)); l; l=l->next) |
then things started crashing, and it was a few hours before i made the following:
#define SAFE_FOR_EACH_LINK(x,y,z) Link *(y), *(z); for((y)=LLGetHead(&(x)); (y); (y)=(z))
#define SAFE_LINK_DATA(y,z) (y)->data; (z)=(y)->next |
and ive been using that since, and it works as long as you get the data before you kill the link
like so:
SAFE_FOR_EACH_LINK(list,l,ll)
{
Data *d=SAFE_LINK_DATA(l,ll);
if(d->p == p) LLRemove(&list,d);
} |
i like it :P _________________ SSC Distension Owner
SSCU Trench Wars Developer |
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 09, 2011 8:39 am Post subject: |
|
|
|
|
Cheese, FOR_EACH does that in one line, uses one fewer variable, and doesn't require you to change the compiler to C99.
Perhaps you misunderstood Arnk's reply to mean the exact opposite of what he said? _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 09, 2011 3:51 pm Post subject: |
|
|
|
|
isnt it already in c99?
if not why cant i do
for(int i=0; i<10; i++)?
also, i never looked at the existing macros too hard because i was always just using
Link *l; for(l=LLGetHead(&list); l; l=l->next)
all the time, and then wrote my own when that stopped working D: |
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 09, 2011 7:15 pm Post subject: |
|
|
|
|
Cheese wrote: | isnt it already in c99? |
Not on every platform.
Cheese wrote: | if not why cant i do
for(int i=0; i<10; i++)? |
Because it's not C99 on your platform.
Cheese wrote: | also, i never looked at the existing macros too hard because i was always just using
Link *l; for(l=LLGetHead(&list); l; l=l->next)
all the time, and then wrote my own when that stopped working D: |
No one expects you to look at code that isn't useful to you, but we all appreciate it when you read a two month old thread before bumping. |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Jan 10, 2011 2:05 pm Post subject: |
|
|
|
|
Still in the field of linked lists...
On Windows, my server was crashing once in a while, and I never knew why. On Linux it crashed much more frequently, and the backtrace allowed me to find the source. Just to be sure...
If I declare a linked list as a global variable in a module (or an array of linked lists), I need to call:
LLInit(&mylist); somewhere in the module load or attach,
and
LLEmpty(&mylist); somewhere in the unload or detach?
I was using LLFree on unload... upon further reading the comments I saw it was pretty bad It was trying to free the variable itself... |
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
|
Back to top |
|
|
|