سؤال

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