We use cookies to improve your experience, for authentication and to ensure that we show you advertising that is relevant to you. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on Ideone website. However, if you wish, you can change cookie settings of your browser at any time.
Embed source code on your page
source code clone
download
copy to clipboard
report bug / make suggestion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>
struct foo {
int a, b, c;
LIST_ENTRY( foo) pointers;
} ;
LIST_HEAD( foo_list, foo) ;
int main( void )
{
LIST_HEAD( foo_list, foo) head;
LIST_INIT( & head) ;
struct foo * item = malloc ( sizeof ( struct foo) ) ;
item-> a = 69 ;
item-> b = 123 ;
LIST_INSERT_HEAD( & head, item, pointers) ;
LIST_FOREACH( item, & head, pointers)
{
printf ( "a = %d b = %d\n " , item-> a, item-> b) ;
}
while ( ! LIST_EMPTY( & head) )
{
item = LIST_FIRST( & head) ;
LIST_REMOVE( item, pointers) ;
free ( item) ;
}
return ( 0 ) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN5cy9xdWV1ZS5oPgoKc3RydWN0IGZvbyB7CiAgICBpbnQgYSwgYiwgYzsKICAgIExJU1RfRU5UUlkoZm9vKSBwb2ludGVyczsKfTsKCkxJU1RfSEVBRChmb29fbGlzdCwgZm9vKTsKCmludCBtYWluKHZvaWQpCnsKICAgIExJU1RfSEVBRChmb29fbGlzdCwgZm9vKSBoZWFkOwoKICAgIExJU1RfSU5JVCgmaGVhZCk7CgogICAgc3RydWN0IGZvbyAqaXRlbSA9IG1hbGxvYyhzaXplb2Yoc3RydWN0IGZvbykpOwogICAgaXRlbS0+YSA9IDY5OwogICAgaXRlbS0+YiA9IDEyMzsKICAgIExJU1RfSU5TRVJUX0hFQUQoJmhlYWQsIGl0ZW0sIHBvaW50ZXJzKTsKCiAgICBMSVNUX0ZPUkVBQ0goaXRlbSwgJmhlYWQsIHBvaW50ZXJzKQogICAgewogICAgICAgIHByaW50ZigiYSA9ICVkIGIgPSAlZFxuIiwgaXRlbS0+YSwgaXRlbS0+Yik7CiAgICB9CgogICAgd2hpbGUgKCFMSVNUX0VNUFRZKCZoZWFkKSkKICAgIHsKICAgICAgICBpdGVtID0gTElTVF9GSVJTVCgmaGVhZCk7CiAgICAgICAgTElTVF9SRU1PVkUoaXRlbSwgcG9pbnRlcnMpOwogICAgICAgIGZyZWUoaXRlbSk7CiAgICB9CgogICAgcmV0dXJuICgwKTsKfQo=
clone
download
copy to clipboard
input / output show all
hide all
upload with new input
result:
Success
time: 0s
memory: 1920 kB
returned value: 0
result:
Success
time: 0s
memory: 1920 kB
returned value: 0
result:
Success
time: 0.01s
memory: 1852 kB
returned value: 0
input: no
result:
Success
time: 0.01s
memory: 1852 kB
returned value: 0
result:
Success
time: 0.01s
memory: 1808 kB
returned value: 0
result:
Success
time: 0s
memory: 1852 kB
returned value: 0
input: no
Choose your language:
Help us translate Ideone - click here