"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: const-ify tables
To:
gameoftrees@openbsd.org
Date:
Wed, 16 Feb 2022 20:32:29 +0100

Download raw body.

Thread
  • Stefan Sperling:

    const-ify tables

  • Ted Bullock:
    
    > #define GOT_HISTEDIT_PICK 'p'
    > to
    > const char GOT_HISTEDIT_PICK = 'p';
    
    For starters, this is thoroughly unidiomatic for OpenBSD(-adjacent)
    code.
    
    > I've actually been wondering about this kind of thing for a long time.
    > Obviously preprocessor directives get written directly into the
    > executable code, whereas readonly const variables are stored elsewhere
    > and as variables their address can be taken.
    
    The compiler will use them as constants as well, but also initialize
    (read-only) storage with them.  The latter is pointless if you do
    not want to take their address.  It also precludes use in header
    files that are included by several source files since you would end
    up with multiple conflicting definitions of the same symbol.
    
    $ cat t.c
    const int ten = 10;
    
    int
    f(int x)
    {
            return x + ten;
    }
    $ cc -c t.c
    $ objdump -td t.o
    ...
    0000000000000000 g     O .rodata        0000000000000004 ten
    ...
       b:   55                      push   %rbp
       c:   48 89 e5                mov    %rsp,%rbp
       f:   89 7d fc                mov    %edi,0xfffffffffffffffc(%rbp)
      12:   8b 45 fc                mov    0xfffffffffffffffc(%rbp),%eax
      15:   83 c0 0a                add    $0xa,%eax
      18:   5d                      pop    %rbp
    ...
    
    -- 
    Christian "naddy" Weisgerber                          naddy@mips.inka.de
    
    
    
  • Stefan Sperling:

    const-ify tables