Beanstalkd: README: add that beanstalkd requires C99 compatible compiler

Created on 13 Jul 2019  Â·  10Comments  Â·  Source: beanstalkd/beanstalkd

Keith, one question. Did you build beanstalkd with C89 in mind? I am asking because I have merged some changes that do not conform to C89 and not sure if I have made a mistake there. I just realized that you were following C89 with variable declaration. I could not find anything mentioned in this repo or in docs about C89. But I see that we use types like uint32_t, then most probably compiler should be "modern", at least C99 and since we are not doing OS stuff here, we might be safe to assume C99 support.

I see that great C programs (git, SQLite) are C89 compilers compatible. For Linux Kernel it seems very important, but I am not sure if there is a need for program like beanstalkd.

What is your opinion on this matter?

Documentation NeedsFix

Most helpful comment

Right now sources can be compiled with -std=c89 and -std=c99. I have no changed anything. And I am not going to propose adding those parameters to the Makefile. This ticket is mostly to decide what kind of features do we want to use. Since we do not support Windows we can use c99 freely as most if not all major compiler/versions support almost whole set of c99 features.

Repeating myself, I am interested in the standard that should be followed by developers here. I proposed to use C99 because it has some features simplifying life of programmers. There is a lack of contributors to this project and making contributors happy is the most important thing to me right now.

All 10 comments

My 2 cents. If you want to write _fully portable code_, w/o any exception, then you should to use C89 (old ANSI C standard). As far as I know, only few compilers supports C99 completely (neither gcc nor clang). Finally C99 has been withdrawn by both ANSI/INCITS and ISO/IEC in favor of C11.

Btw, it would be useful to have a page (wiki?) with a description of supported compilers, platforms, language standards and so on.

Thank you. I have investigated the sources prior my involvement into the project. I see that some of the C99 features were used before. Things like stdint.h, variables declared in the middle of a block, but not designated initializers. It means that existing sources required some kind of support of C99 already.

Btw, it would be useful to have a page (wiki?) with a description of supported compilers, platforms, language standards and so on.

I would like to put that in README.md since we have some of it there (OS). It is good that this project never claimed to be C89 compatible.

Maybe, we could extend the matrix with different versions of gcc and clang from here: https://docs.travis-ci.com/user/languages/cpp/#gcc-on-linux and we could mention what version do we test against.

Alright, another data point in this saga:

Trying to switch on Wextra lead to some weird errors from gcc 4.8.* when optimization is turned on. Right now I am thinking that C99 is a bad thing. Even when there are designated initializer all over the place, some old compilers complain about some fields. This is the example:

static int
mustdiallocal(int port)
{
    struct sockaddr_in addr = {
        .sin_family = AF_INET,
        .sin_port = htons(port),
    };

gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4:

testserv.c: In function ‘mustdiallocal’:
testserv.c:66:5: error: missing initializer for field ‘sin_addr’ of ‘struct sockaddr_in’ [-Werror=missing-field-initializers]
     };
     ^
In file included from /usr/include/netdb.h:27:0,
                 from testserv.c:11:
/usr/include/netinet/in.h:241:20: note: ‘sin_addr’ declared here
     struct in_addr sin_addr;  /* Internet address.  */
                    ^

Shouldn't we provide the possibility to use both standards?

My point is to have official support of "minimal compatible language version", e.g. C89. If it is impossible or/and irrelevant let's use C99 then. But the most important thing is to understand (and declare) the minimum possible version. Probable we would like to have to understanding what the maximum supported version of the language standard is, but IMO it is a secondary question.

@kr thoughts?

Right now sources can be compiled with -std=c89 and -std=c99. I have no changed anything. And I am not going to propose adding those parameters to the Makefile. This ticket is mostly to decide what kind of features do we want to use. Since we do not support Windows we can use c99 freely as most if not all major compiler/versions support almost whole set of c99 features.

Repeating myself, I am interested in the standard that should be followed by developers here. I proposed to use C99 because it has some features simplifying life of programmers. There is a lack of contributors to this project and making contributors happy is the most important thing to me right now.

Sorry for not replying sooner.

For a while, I had been trying to stick to C89 (in -pedantic mode), but I suspect that's not worth the trouble. How many of beanstalkd's users need to compile it with anything other than a new-ish gcc or clang? I suspect the number is vanishingly small. I agree with everything you said in https://github.com/beanstalkd/beanstalkd/issues/465#issuecomment-511733607.

C99 sounds pretty good, or maybe even "whatever subset of C11 is supported by both gcc and clang".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ysmolsky picture ysmolsky  Â·  4Comments

JensRantil picture JensRantil  Â·  11Comments

zimbatm picture zimbatm  Â·  7Comments

sergeyklay picture sergeyklay  Â·  11Comments

PatriciaSVMonteiro picture PatriciaSVMonteiro  Â·  14Comments