When using JNI to interface between Java and C, javah parses a boolean value in Java to jBoolean in the JNI header file. When I use bool in the C file, the Visual studio compiler throws a warning that
warning C4800: ‘jboolean’ : forcing value to bool ‘true’ or ‘false’ (performance warning)
Is there any other data type that should be used? Or if bool is the only data type here, what exactly are the performance problems that I might face?
The “performance problem” is that the cast isn’t completely free. Casting to
boolessentially means forcing all non-zero values to1, which takes a tiny bit of code, as opposed to a “free” cast like wideningchartoint. The “performance problem” is a few extra machine instructions. If you’re doing this a million times in a tight loop, OK, maybe you care — otherwise, no, you shouldn’t care at all. This is IMO a silly compiler warning; that small added cost is simply part of the compromise you make when usingbooland the compiler shouldn’t be bothering you about it.