문제

In the android implementation of OpenSL ES, the following example code can be found in the android-ndk /samples/native-audio/jni/native-audio-jni.c

SLresult result;
result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
assert(SL_RESULT_SUCCESS == result);
(void)result;

The SLResult is defined to be of type SLuint32, which by definition is a 32-bit unsigned integer type.

My question is: what does the line (void)result; do? I thought this would do nothing, and a compiler could optimize this away. However, similar line appears in many places in the example, and I am left wondering whether it has some importance after all.

도움이 되었습니까?

해결책

That kind of silly code is sometimes inserted to silence compiler or lint warnings, such as "variable result is not used" when assertion-checking is turned off.

I did not write the code, so I cannot be certain, but that is my guess.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top