u/LagutTV

▲ 25 r/Zig

Can you do extern in Zig like you would in C

Hi everyone,

I'm experimenting with a copy-and-patch stencil system and currently write my stencils in C. I need optimizer-opaque and hoistable holes. In C I found success with extern const + hidden. I'm looking for potentially porting those stencils to Zig but I'm struggling with finding a hole mechanism.

Here is an example:

#include <stdint.h>
    
extern const int64_t placeholder __attribute__((visibility("hidden")));
    
void filter_gt(const int64_t * restrict input, int64_t * restrict output, int32_t size, int32_t *out_size) {
  int32_t count = 0;    
  for (int32_t i = 0; i < size; ++i) {
    if (placeholder < input[i]) {
      output[count++] = input[i];
    }
  }
  *out_size = count;
}

For now I'm focusing on Mach-O and this generates a PAGE21/PAGEOFF12 LOAD. I'm trying to avoid GOT - but I believe that would be the potential alternative if I wanted to use Zig.

reddit.com
u/LagutTV — 9 days ago