It’s scary to see that the following function (which is referred and called in another function) didn’t generate any compilation error or warning:
bool GameController::onTouchBegan(Touch* touch, Event* event)
{
auto hand = static_cast<Hand*>(event->getCurrentTarget());
log("DEBUG onTouchBegan %d", hand->getTag());
}
I was debugging another issue when I realize that it missed a return statement. I was under the impression that the compiler should fail such a case?
I suppose compiler should have given compile time warning but since the warnings would be off so it’s not showing those error. Anyways, in such case when you’ve missed the “proper” return statement then you can get unexpected results. Even return; would be treated as “not proper” return statement in this case as it expects boolean.
In case you get time, just go to compiler settings and try to turn on warnings for gcc and see if that gives your warnings at run time! I wonder which code editor, you use!
I’m using Android Studio but using the trick described in this video: https://www.youtube.com/watch?v=gdOkbXYsf04. Basically, I open two Android Studios, one for building and running the game, the other for editing the source file. I wonder if anyone has successfully turned on the intelligent assistance in the second one. Obviously in my case I can use some help from the IDE there.
EDIT:
Sorry I realized that i’m missing the greater context here. I am using cocos2d-x 3.9 which supports android project with a Macbook. And I’m using the cocos command to compile. Sadly, after reading the help, I don’t think I see any switch to “turn on warnings for gcc”:
$ cocos compile --help
usage: cocos compile [-h] [-s SRC_DIR] [-q] [-p PLATFORM] [--list-platforms]
[--proj-dir PROJ_DIR] [-m MODE] [-j JOBS] [-o OUTPUT_DIR]
[--ap ANDROID_PLATFORM] [--ndk-mode NDK_MODE]
[--app-abi APP_ABI] [--ndk-toolchain TOOLCHAIN]
[--ndk-cppflags CPPFLAGS] [--android-studio] [--no-apk]
[--vs VS_VERSION] [--source-map] [--advanced]
[-t TARGET_NAME] [--sign-identity SIGN_ID] [--no-res]
[--compile-script {0,1}] [--lua-encrypt]
[--lua-encrypt-key LUA_ENCRYPT_KEY]
[--lua-encrypt-sign LUA_ENCRYPT_SIGN]
Compile projects to binary.
optional arguments:
-h, --help show this help message and exit
-s SRC_DIR, --src SRC_DIR
Specify the path of the project.
-q, --quiet Less output
-p PLATFORM, --platform PLATFORM
Specify the target platform.
--list-platforms List available platforms
--proj-dir PROJ_DIR Specify the directory for target platform.
-m MODE, --mode MODE Set the compiling mode, should be debug|release,
default is debug.
-j JOBS, --jobs JOBS Allow N jobs at once.
-o OUTPUT_DIR, --output-dir OUTPUT_DIR
Specify the output directory.
Android Options:
--ap ANDROID_PLATFORM
Specify the Android platform used for building Android
apk.
--ndk-mode NDK_MODE Set the compiling mode of ndk-build, should be
debug|release|none, native code will not be compiled
when the value is none. Default is same value with
'-m'.
--app-abi APP_ABI Set the APP_ABI of ndk-build.Can be multi value
separated with ':'. Sample : --app-aib
armeabi:x86:mips. Default value is 'armeabi'.
--ndk-toolchain TOOLCHAIN
Specify the NDK_TOOLCHAIN of ndk-build.
--ndk-cppflags CPPFLAGS
Specify the APP_CPPFLAGS of ndk-build.
--android-studio Use the Android Studio project for Android platform.
--no-apk Not generate the apk file.
Windows Options:
--vs VS_VERSION Specify the Visual Studio version will be used. Such
as: 2013. Default find available version
automatically.
Web Options:
--source-map Enable source-map
--advanced Compile all source js files using Closure Compiler's
advanced mode, bigger compression ratio bug more risk.
iOS/Mac Options:
-t TARGET_NAME, --target TARGET_NAME
Specify the target name to be compiled.
iOS Options:
--sign-identity SIGN_ID
The code sign identity for iOS.
lua/js project Options:
--no-res Package without project resources.
--compile-script {0,1}
Diable/Enable the compiling of lua/js script files.
lua project Options:
--lua-encrypt Enable the encrypting of lua scripts.
--lua-encrypt-key LUA_ENCRYPT_KEY
Specify the encrypt key for the encrypting of lua
scripts.
--lua-encrypt-sign LUA_ENCRYPT_SIGN
Specify the encrypt sign for the encrypting of lua
scripts.
$
And I’m not aware of environment variable which can get gcc to print out warning messages or treat warnings as errors. If anyone knows, please advice me.