On Mon, 24 Apr 2023, Harald van Dijk wrote:
coreutils/readlink.c:91:27: warning: adding 'unsigned int' to a string does not append to the string [-Wstring-plus-int]
       printf("%s%s", buf, "\n" + (opt & 1));
                           ~~~~~^~~~~~~~~~~
coreutils/readlink.c:91:27: note: use array indexing to silence this warning
       printf("%s%s", buf, "\n" + (opt & 1));
                                ^
                           &    [          ]

I am not sure what busybox's intent is here. If busybox decides that this warning is useless, it would be nice if it got suppressed reliably.

Alternatively, avoid warnings with this construction which gives pretty
good size results:

        if (opt)
            fputs(buf, stdout);
        else
            puts(buf);



The rest of this email is cc/size experiment results.

    $ ./cc-size  -c f1.c -Os
    cc -c f1.c -Os
                -DT0  -DT1  -DT2  -DT3
    aarch64     1584   -80    -8   +48
    arm         1008   -48   -20    +0
    mips        1396   -72    +8   +64
    x86_64      1520   -80   -32    +0
    gcc         1552   -96    +8   +72
    clang       1280   -80    +0   +72

The numbers represent the increase in byte size of f1.o compared to when
compiled with baseline -DT0.

    $ cat f1.c
    #include <stdio.h>

    /* suppress trailing newline when opt */
    int f1(int opt, char buf[]) {
    #if defined(T0)
        if (opt) printf("%s", buf); else printf("%s\n", buf);
    #elif defined(T1)
        if (opt) fputs(buf, stdout); else puts(buf);
    #elif defined(T2)
        printf("%s%s", buf, "\n" + (opt & 1));
    #elif defined(T3)
        printf("%s%s", buf, opt ? "" : "\n");
    #else
    # error "forgot to -DTx"
    #endif
    }

The compilers were:

    aarch64-linux-musl-gcc (GCC) 11.2.0
    arm-linux-musleabi-gcc (GCC) 11.2.0
    mips-linux-musl-gcc (GCC) 11.2.0
    x86_64-linux-musl-gcc (GCC) 11.2.0
    gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
    Ubuntu clang version 14.0.0-1ubuntu1 (x86_64-pc-linux-gnu)

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to