C99 is now the C standard for all our C code.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sun, 22 Nov 2015 16:12:54 +0000 (17:12 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sun, 22 Nov 2015 21:31:22 +0000 (22:31 +0100)
The main new feature is mixed variable declarations and code, which can help
reduce uninitialized variables or accidental variable reuse.

Due to incomplete C99 support in VS 2013, variable length arrays are not
supported, BLI_array_alloca must still be used. The header <tgmath.h> is also
not supported.

Differential Revision: https://developer.blender.org/D1631

CMakeLists.txt
SConstruct
build_files/scons/config/darwin-config.py
build_files/scons/config/linux-config.py
build_files/scons/config/win32-mingw-config.py
build_files/scons/config/win64-mingw-config.py
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/python/mathutils/mathutils_Matrix.c

index 14eb2af58a45340a931aa3c73c983df2207c38df..b5317ccb72495f2a5213072e97917ffc804dec7d 100644 (file)
@@ -1189,12 +1189,6 @@ if(UNIX AND NOT APPLE)
        if(CMAKE_COMPILER_IS_GNUCC)
                set(PLATFORM_CFLAGS "-pipe -fPIC -funsigned-char -fno-strict-aliasing")
 
-               if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_LESS "5.0")
-                       # GCC5 uses gnu11, until we update, force c89
-                       # though some c11 features can still be used.
-                       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu89")
-               endif()
-
                # use ld.gold linker if available, could make optional
                execute_process(
                        COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version
@@ -2577,9 +2571,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
 
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_CAST_ALIGN -Wcast-align)
-       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
+       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_VLA -Werror=vla)
        # system headers sometimes do this, disable for now, was: -Werror=strict-prototypes
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_STRICT_PROTOTYPES  -Wstrict-prototypes)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_MISSING_PROTOTYPES -Wmissing-prototypes)
@@ -2624,7 +2618,6 @@ if(CMAKE_COMPILER_IS_GNUCC)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_DIV_BY_ZERO -Wno-div-by-zero)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_TYPE_LIMITS -Wtype-limits)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
-       ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_CHAR_SUBSCRIPTS -Wno-char-subscripts)
        ADD_CHECK_CXX_COMPILER_FLAG(CXX_WARNINGS CXX_WARN_NO_UNKNOWN_PRAGMAS -Wno-unknown-pragmas)
@@ -2661,7 +2654,6 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
 
        # strange, clang complains these are not supported, but then yses them.
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ALL -Wall)
-       ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_DECLARATION_AFTER_STATEMENT -Werror=declaration-after-statement)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_IMPLICIT_FUNCTION_DECLARATION -Werror=implicit-function-declaration)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_ERROR_RETURN_TYPE  -Werror=return-type)
        ADD_CHECK_C_COMPILER_FLAG(C_WARNINGS C_WARN_NO_AUTOLOGICAL_COMPARE -Wno-tautological-compare)
@@ -2776,6 +2768,13 @@ if(WITH_CPP11)
        endif()
 endif()
 
+if(MSVC)
+       # Visual Studio has all standards it supports available by default
+else()
+       # Use C99 + GNU extensions, works with GCC, Clang, ICC
+       set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+endif()
+
 # Include warnings first, so its possible to disable them with user defined flags
 # eg: -Wno-uninitialized
 set(CMAKE_C_FLAGS "${C_WARNINGS} ${CMAKE_C_FLAGS} ${PLATFORM_CFLAGS}")
index ebd9cd1ec901bf1482af2ca0adf0246f2a3c9f24..29f539236c2111ab3c352183876c1d3a3b95c0d3 100644 (file)
@@ -498,6 +498,13 @@ if env['WITH_BF_CPP11']:
     else:
         env['CXXFLAGS'].append('-std=c++11')
 
+if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
+    # Visual Studio has all standards it supports available by default
+    pass
+else:
+    # Use C99 + GNU extensions, works with GCC, Clang, ICC
+    env['CFLAGS'].append('-std=gnu99')
+
 #check for additional debug libnames
 
 if env.has_key('BF_DEBUG_LIBS'):
index 0bf03a46bd29f2db1e558d6e6c39595cd14b7f55..16ba3ec4133ea3b1c4003563299d600625714314 100644 (file)
@@ -248,7 +248,7 @@ REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
 CC_WARN = ['-Wall']
-C_WARN = ['-Wno-char-subscripts', '-Wpointer-arith', '-Wcast-align', '-Wdeclaration-after-statement', '-Wno-unknown-pragmas', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wpointer-arith', '-Wcast-align', '-Wvla', '-Wno-unknown-pragmas', '-Wstrict-prototypes']
 CXX_WARN = ['-Wno-invalid-offsetof', '-Wno-sign-compare']
 
 ##FIX_STUBS_WARNINGS = -Wno-unused
index ff8ecf0aa72bcbb4b5a8fb9722ca56d97fb804d0..1990d6ece0a9538787324ed611f1b48647e606ef 100644 (file)
@@ -254,7 +254,7 @@ REL_CFLAGS = []
 REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wunused-parameter', '-Wstrict-prototypes', '-Werror=declaration-after-statement', '-Werror=implicit-function-declaration', '-Werror=return-type']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wunused-parameter', '-Wstrict-prototypes', '-Werror=vla', '-Werror=implicit-function-declaration', '-Werror=return-type']
 CC_WARN = ['-Wall']
 CXX_WARN = ['-Wno-invalid-offsetof', '-Wno-sign-compare']
 
index 552a1a5cec3946c14dab4221b8737e312971dd8e..f4b709dda81b071f4a7cf1e44052b2f307164df9 100644 (file)
@@ -202,7 +202,7 @@ REL_CFLAGS = []
 REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2']
 
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wstrict-prototypes']
 
 CC_WARN = [ '-Wall' ]
 
index 87a9b5e4eac3c9b64d8de7f4a7196d9a5bd5d3ce..6106f2ac631ba7f83896aa4814c7e6741e3f2e86 100644 (file)
@@ -197,7 +197,7 @@ REL_CXXFLAGS = []
 REL_CCFLAGS = ['-O2', '-ftree-vectorize']
 
 # NOTE: C_WARN seems to get ignored - at least -Wno-char-subscripts doesn't work!
-C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-prototypes']
+C_WARN = ['-Wno-char-subscripts', '-Wvla', '-Wstrict-prototypes']
 
 CC_WARN = [ '-Wall', '-Wno-char-subscripts' ]
 
index b7742d829914250ae47b123857ea5107f7c400e6..57e37c0190ddb80f4756e73e7299fb437a322a98 100644 (file)
@@ -30,6 +30,9 @@
  */
 
 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#  ifdef __GNUC__
+#    pragma GCC diagnostic ignored "-Wvla"
+#  endif
 #  define USE_DYNSIZE
 #endif
 
index 7ad20d41bf1e33d73498f3739962bb7d5009218f..71288871104d903d04770ee73383ed25d907123c 100644 (file)
@@ -2055,7 +2055,7 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
 
 static Py_hash_t Matrix_hash(MatrixObject *self)
 {
-       float mat[SQUARE(MATRIX_MAX_DIM)];
+       float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
 
        if (BaseMath_ReadCallback(self) == -1)
                return -1;