List comprehensions: Difference between revisions

Content added Content deleted
(→‎Insitux: fix breaking changes)
m (→‎{{header|C}}: 3 syntaxhighlight -> 1 plus comment)
Line 397: Line 397:
C doesn't have a built-in syntax for this, but any problem can be solved if you throw enough macros at it:
C doesn't have a built-in syntax for this, but any problem can be solved if you throw enough macros at it:
{{works with|GCC}}
{{works with|GCC}}
The program below is C11 compliant. For C99 compilers change line 57 :
The program below is C11 compliant. For C99 compilers note the change on line 57 (output remains unchanged).
<syntaxhighlight lang="c">
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }
</syntaxhighlight>
to
<syntaxhighlight lang="c">
int i;
for (i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }
</syntaxhighlight>
Output remains unchanged.
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
#include <stdlib.h>
#include <stdlib.h>
Line 464: Line 455:
List * intRangeList(int f, int t) {
List * intRangeList(int f, int t) {
List * l = listNew(sizeof f, &f), * e = l;
List * l = listNew(sizeof f, &f), * e = l;
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); }
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); } // C11 compliant
//int i;
//for (i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); } // use this for C99
return l;
return l;
}
}