List comprehensions: Difference between revisions

m
→‎{{header|C}}: 3 syntaxhighlight -> 1 plus comment
(→‎Insitux: fix breaking changes)
m (→‎{{header|C}}: 3 syntaxhighlight -> 1 plus comment)
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:
{{works with|GCC}}
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">
#include <stdlib.h>
Line 464 ⟶ 455:
List * intRangeList(int f, int t) {
List * l = listNew(sizeof f, &f), * e = l;
for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); } // C11 compliant
//int i;
//for (int i = f + 1; i <= t; i ++) { e = e->nx = listNew(sizeof i, &i); } // use this for C99
return l;
}
7,796

edits