Super Lint
Miles
_______ at _______.____
Wed Sep 20 18:00:09 PDT 2006
Walter Bright wrote:
> I've been interested in various ideas for static checking for common bug
> patterns for D. For example:
>
> for (int i = 0; i < 10; i++)
> { foo();
> break;
> }
>
> would be flagged as a suspicious use of break. Are there any legitimate
> uses of break in this manner? Any thoughts and ideas in this direction?
Yes, there are. Once I had this problem:
Obj *v[n], **p;
for (p = v; *p != NULL; p++) {
do_something(*p);
if (condition1(*p))
continue; /* failed */
do_something_else(*p);
if (condition2(*p))
continue; /* failed */
...
do_the_last_thing(*p);
if (conditionN(*p))
continue; /* failed */
break; /* good! */
}
if (*p != NULL)
return *p;
else
throw NoSuitableIndividual;
It was an AI application. This function returns the first Obj in array
'v' which survives all 17 conditions of a natural selection process. Of
course, the last condition could be rewritten as something like:
...
if (!conditionN(*p))
return *p; /* good! */
}
...
But it is just an example.
More information about the Digitalmars-d
mailing list