T
Tomás Ó hÉilidhe
Is there any sort of tool out there that can warn about code that can
behave differently depending on "unspecified" behaviour? For instance,
take the following statement:
*p++ = ConvertToLowercase(*p);
In this statement, we don't know whether the lefthand or the righthand
side will be evaluated first. If the righthand side is first to be
evaluated, then we get:
*p = ConvertToLowercase(*p);
p = p + 1;
If the lefthand side is evaluated first, we get:
p = p + 1;
*p = ConvertToLowercase(*p);
The original statement has two possible distinct behaviours depending
on how the compiler chooses to handle the "unspecified" behaviour.
Is there any sort of tool that can go through code and warn about
instances in which "unspecified" behaviour can result in two or more
different behaviours?
gcc is neat in that it warns about a sequence point violation; for
instance if you do the following:
i++ + i++
then you get:
test.c:5: warning: operation on `i' may be undefined
Just wondering if there's a tool that will warn about unspecified
order of evaluation, or any unspecified behaviour for that matter.
behave differently depending on "unspecified" behaviour? For instance,
take the following statement:
*p++ = ConvertToLowercase(*p);
In this statement, we don't know whether the lefthand or the righthand
side will be evaluated first. If the righthand side is first to be
evaluated, then we get:
*p = ConvertToLowercase(*p);
p = p + 1;
If the lefthand side is evaluated first, we get:
p = p + 1;
*p = ConvertToLowercase(*p);
The original statement has two possible distinct behaviours depending
on how the compiler chooses to handle the "unspecified" behaviour.
Is there any sort of tool that can go through code and warn about
instances in which "unspecified" behaviour can result in two or more
different behaviours?
gcc is neat in that it warns about a sequence point violation; for
instance if you do the following:
i++ + i++
then you get:
test.c:5: warning: operation on `i' may be undefined
Just wondering if there's a tool that will warn about unspecified
order of evaluation, or any unspecified behaviour for that matter.