To: vim_dev@googlegroups.com Subject: Patch 8.0.1730 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1730 Problem: No configure check for the used C99 features. Solution: Add a compilation check. Tentatively document C99 features. Files: src/configure.ac, src/auto/configure, runtime/doc/develop.txt *** ../vim-8.0.1729/src/configure.ac 2018-04-15 16:03:12.771985437 +0200 --- src/configure.ac 2018-04-17 21:56:08.855964875 +0200 *************** *** 29,34 **** --- 29,57 ---- AC_HEADER_STDC 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 ], [ + 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. AC_MSG_CHECKING(--enable-fail-if-missing argument) *** ../vim-8.0.1729/src/auto/configure 2018-04-15 16:03:12.775985408 +0200 --- src/auto/configure 2018-04-17 21:56:11.619945565 +0200 *************** *** 4179,4184 **** --- 4179,4218 ---- 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 + 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_n "checking --enable-fail-if-missing argument... " >&6; } *** ../vim-8.0.1729/runtime/doc/develop.txt 2016-09-12 12:45:25.000000000 +0200 --- runtime/doc/develop.txt 2018-04-17 21:59:20.214627248 +0200 *************** *** 143,151 **** VIM IS... NOT *design-not* ! - Vim is not a shell or an Operating System. You will not be able to run a ! shell inside Vim or use it to control a debugger. This should work the ! other way around: Use Vim as a component from a shell or in an IDE. A satirical way to say this: "Unlike Emacs, Vim does not attempt to include everything but the kitchen sink, but some people say that you can clean one with it. ;-)" --- 143,152 ---- VIM IS... NOT *design-not* ! - Vim is not a shell or an Operating System. It does provide a terminal ! window, in which you can run a shell or debugger. E.g. to be able to do ! this over an ssh connection. But if you don't need a text editor with that ! it is out of scope (use something like screen or tmux instead). A satirical way to say this: "Unlike Emacs, Vim does not attempt to include everything but the kitchen sink, but some people say that you can clean one with it. ;-)" *************** *** 177,192 **** 5. Make a patch with "git diff". You can also create a pull request on github, but it's the diff that matters. 6. Make a note about what changed, preferably mentioning the problem and the ! solution. Send an email to the vim-dev maillist with an explanation and include the diff. Or create a pull request on github. C COMPILER *style-compiler* 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. ! One restriction that this implies: no // comments, only /* comments */. USE OF COMMON FUNCTIONS *style-functions* --- 178,233 ---- 5. Make a patch with "git diff". You can also create a pull request on github, but it's the diff that matters. 6. Make a note about what changed, preferably mentioning the problem and the ! solution. Send an email to the |vim-dev| maillist with an explanation and include the diff. Or create a pull request on github. C COMPILER *style-compiler* The minimal C compiler version supported is C89, also known as ANSI C. ! 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). ! 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* *** ../vim-8.0.1729/src/version.c 2018-04-17 20:14:35.831140930 +0200 --- src/version.c 2018-04-17 21:58:00.151187068 +0200 *************** *** 764,765 **** --- 764,767 ---- { /* Add new patch number below this line */ + /**/ + 1730, /**/ -- "You mean there really is an answer?" "Yes! But you're not going to like it!" "Oh do please tell us!" "You're really not going to like it!" "but we MUST know - tell us" "Alright, the answer is...." "yes..." "... is ..." "yes... come on!" "is 42!" (Douglas Adams - The Hitchhiker's Guide to the Galaxy) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///