patch 8.0.1730: no configure check for the used C99 features
Problem: No configure check for the used C99 features. Solution: Add a compilation check. Tentatively document C99 features.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
*develop.txt* For Vim version 8.0. Last change: 2017 Jul 31
|
*develop.txt* For Vim version 8.0. Last change: 2018 Apr 17
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -185,9 +185,49 @@ The basic steps to make changes to the code:
|
|||||||
C COMPILER *style-compiler*
|
C COMPILER *style-compiler*
|
||||||
|
|
||||||
The minimal C compiler version supported is C89, also known as ANSI C.
|
The minimal C compiler version supported is C89, also known as ANSI C.
|
||||||
Later standards don't add much and C89 is the widest supported.
|
Later standards, such as C99, are not widely supported, or at least not 100%
|
||||||
|
supported. Therefore we use only some of the C99 features and disallow some
|
||||||
|
(at least for now).
|
||||||
|
|
||||||
One restriction that this implies: no // comments, only /* comments */.
|
Please don't make changes everywhere to use the C99 features, it causes merge
|
||||||
|
problems for existing patches. Only use them for new and changed code.
|
||||||
|
|
||||||
|
Comments ~
|
||||||
|
|
||||||
|
Traditionally Vim uses /* comments */. We intend to keep it that way,
|
||||||
|
especially for file and function headers. For new code or lines of code that
|
||||||
|
change, it is allowed to use // comments. Especially when it comes after
|
||||||
|
code:
|
||||||
|
int some_var; // single line comment useful here
|
||||||
|
|
||||||
|
Enums ~
|
||||||
|
|
||||||
|
The last item in an enum may have a trailing comma. C89 didn't allow this.
|
||||||
|
|
||||||
|
Types ~
|
||||||
|
|
||||||
|
"long long" is allowed and can be expected to be 64 bits. Use %lld in printf
|
||||||
|
formats. Also "long long unsigned" with %llu.
|
||||||
|
|
||||||
|
Flexible array members ~
|
||||||
|
|
||||||
|
This is an array without size, used as the last member of a struct. Vim used
|
||||||
|
to have an array of size one, which causes trouble with FORTIFY_SOURCE. Using
|
||||||
|
an "unsized array" is the intended use, we will change all of them.
|
||||||
|
struct some_stuff {
|
||||||
|
size_t length;
|
||||||
|
char payload[]; // will have size "length"
|
||||||
|
};
|
||||||
|
|
||||||
|
Not to be used ~
|
||||||
|
|
||||||
|
These C99 features are not to be used, because not enough compilers support
|
||||||
|
them:
|
||||||
|
- Declaration after Statements (MSVC 2012 does not support it). All
|
||||||
|
declarations need to be at the start of the block.
|
||||||
|
- Variable length arrays (even in C11 this is an optional feature).
|
||||||
|
- _Bool and _Complex types.
|
||||||
|
- "inline" (it's hardly ever needed, let the optimizer do its work)
|
||||||
|
|
||||||
|
|
||||||
USE OF COMMON FUNCTIONS *style-functions*
|
USE OF COMMON FUNCTIONS *style-functions*
|
||||||
|
|||||||
34
src/auto/configure
vendored
34
src/auto/configure
vendored
@ -4179,6 +4179,40 @@ $as_echo "#define HAVE_SYS_WAIT_H 1" >>confdefs.h
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the compiler can handle Vim code" >&5
|
||||||
|
$as_echo_n "checking if the compiler can handle Vim code... " >&6; }
|
||||||
|
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||||
|
/* end confdefs.h. */
|
||||||
|
#include <stdio.h>
|
||||||
|
int
|
||||||
|
main ()
|
||||||
|
{
|
||||||
|
|
||||||
|
struct with_flexible_member {
|
||||||
|
int count; // comment
|
||||||
|
char text[]; // another comment
|
||||||
|
};
|
||||||
|
enum {
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
three,
|
||||||
|
};
|
||||||
|
long long int a = 1;
|
||||||
|
long long unsigned b = 2;
|
||||||
|
printf("a %lld and a %llu", a, b);
|
||||||
|
|
||||||
|
;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
_ACEOF
|
||||||
|
if ac_fn_c_try_compile "$LINENO"; then :
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||||
|
$as_echo "yes" >&6; }
|
||||||
|
else
|
||||||
|
as_fn_error $? "compiler does not work properly - see auto/config.log" "$LINENO" 5
|
||||||
|
fi
|
||||||
|
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||||
|
|
||||||
|
|
||||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking --enable-fail-if-missing argument" >&5
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking --enable-fail-if-missing argument" >&5
|
||||||
$as_echo_n "checking --enable-fail-if-missing argument... " >&6; }
|
$as_echo_n "checking --enable-fail-if-missing argument... " >&6; }
|
||||||
|
|||||||
@ -29,6 +29,29 @@ dnl in autoconf needs it, where it uses STDC_HEADERS.
|
|||||||
AC_HEADER_STDC
|
AC_HEADER_STDC
|
||||||
AC_HEADER_SYS_WAIT
|
AC_HEADER_SYS_WAIT
|
||||||
|
|
||||||
|
dnl Check that the C99 features that Vim uses are supported:
|
||||||
|
dnl - // commands
|
||||||
|
dnl - comma after last enum item
|
||||||
|
dnl - "long long int" and "long long unsigned"
|
||||||
|
dnl - flexible array member
|
||||||
|
AC_MSG_CHECKING(if the compiler can handle Vim code)
|
||||||
|
AC_TRY_COMPILE([#include <stdio.h>], [
|
||||||
|
struct with_flexible_member {
|
||||||
|
int count; // comment
|
||||||
|
char text[]; // another comment
|
||||||
|
};
|
||||||
|
enum {
|
||||||
|
one,
|
||||||
|
two,
|
||||||
|
three,
|
||||||
|
};
|
||||||
|
long long int a = 1;
|
||||||
|
long long unsigned b = 2;
|
||||||
|
printf("a %lld and a %llu", a, b);
|
||||||
|
],
|
||||||
|
AC_MSG_RESULT(yes),
|
||||||
|
AC_MSG_ERROR([compiler does not work properly - see auto/config.log]))
|
||||||
|
|
||||||
dnl Check for the flag that fails if stuff are missing.
|
dnl Check for the flag that fails if stuff are missing.
|
||||||
|
|
||||||
AC_MSG_CHECKING(--enable-fail-if-missing argument)
|
AC_MSG_CHECKING(--enable-fail-if-missing argument)
|
||||||
|
|||||||
@ -762,6 +762,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1730,
|
||||||
/**/
|
/**/
|
||||||
1729,
|
1729,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user