Defines | |
#define | nxs_do_onbreak(_cond, _expr) |
Behaves like a do() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of. | |
#define | nxs_for_eachbreak(_init, _cond, _each) |
Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _each even if the loop gets broken out of. | |
#define | nxs_for_onbreak(_init, _cond, _each, _expr) |
Behaves like a for() loop with the arguments _init, _cond, and _each, but evaluates _expr only if the loop gets broken out of. | |
#define | nxs_foreach_array(_var, _array) |
Loops through the items in _array, assigning each to _var and executing the given block of code. | |
#define | nxs_forreach_array(_var, _array) |
Loops in reverse through the items in _array, assigning each to _var and executing the given block of code. | |
#define | nxs_while_onbreak(_cond, _expr) |
Behaves like a while() loop with the argument _cond, but evaluates _expr only if the loop gets broken out of. |
Created by Justin Spahr-Summers on 2007-12-09. Copyright 2007. All rights reserved.
#define nxs_do_onbreak | ( | _cond, | |||
_expr | ) |
Behaves like a do()
loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.
#define nxs_for_eachbreak | ( | _init, | |||
_cond, | |||||
_each | ) |
Behaves like a for()
loop with the arguments _init, _cond, and _each, but evaluates _each even if the loop gets broken out of.
// utterly useless piece of code... never do this // the good news is that it will never leak resources unsigned char *ptr; nxs_for_eachbreak ( ptr = NULL, (ptr = malloc(rand())), free(ptr)) { printf("Allocated %p\n", ptr); if (*ptr == 0) { printf("Found a zero byte, dying\n"); break; } }
#define nxs_for_onbreak | ( | _init, | |||
_cond, | |||||
_each, | |||||
_expr | ) |
Behaves like a for()
loop with the arguments _init, _cond, and _each, but evaluates _expr only if the loop gets broken out of.
// utterly useless piece of code... never do this // the good news is that it will never leak resources char buf[1024]; size_t size = 0; nxs_for_onbreak ( FILE *fd = fopen("text.txt", "r"), size < 1024, size = strlen(buf), fclose(fd)) { if (!fgets(buf, 1024 - size, fd)) break; }
#define nxs_foreach_array | ( | _var, | |||
_array | ) |
Loops through the items in _array, assigning each to _var and executing the given block of code.
int array[] = { 31, 8, 903, -11 }; nxs_foreach_array (int i, array) { printf("%i\n", i); }
#define nxs_forreach_array | ( | _var, | |||
_array | ) |
Loops in reverse through the items in _array, assigning each to _var and executing the given block of code.
int array[] = { 31, 8, 903, -11 }; nxs_forreach_array (int i, array) { printf("%i\n", i); }
#define nxs_while_onbreak | ( | _cond, | |||
_expr | ) |
Behaves like a while()
loop with the argument _cond, but evaluates _expr only if the loop gets broken out of.