Search code examples
c++android-ndkgcc-warningndk-build

Android ndk build: Specifying warning level for both C and C++


I'm compiling with ndk-build (r10e) a library mixing C and C++ files. My mk file has lines:

LOCAL_CPPFLAGS += -Wall
LOCAL_CPPFLAGS += -Wno-unused-parameter
LOCAL_CFLAGS += -Wall
LOCAL_CFLAGS += -Wno-unused-parameter

However, when I compile this code:

void func2()
{
    unsigned int size = 3;
    int pos;
    for ( pos = 0; pos != size; ++pos )
    {

    }
}

In a cpp file, I get expected warning:

file.cpp:4:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for ( int pos = 0; pos != size; ++pos )

In a c file, I don't get any warning...

Isn't LOCAL_CFLAGS the right way to specify warning level for C files? Bonus question: Is there a way to specify warning level for both C and C++ using a simple variables (to avoid duplicating the lines LOCAL_CPPFLAGS/LOCAL_CFLAGS)?


Solution

  • According to section 3.8 Options to Request or Suppress Warnings of the GCC documentation, -Wall only enables -Wsign-compare for C++ code. Fo C code you either need to use -Wextra, or enable -Wsign-compare explicitly.

    Bonus question: Is there a way to specify warning level for both C and C++

    Yes, LOCAL_CFLAGS is applied to both C and C++ code. (source)