Skip to content

C glue generates invalid syntax for fixed-size array parameters #379

@sequencer

Description

@sequencer

When generating C glue code with --c flag, fixed-size array parameters are rendered with incorrect syntax. The array size specifier [N] is placed before the parameter name instead of after.

Reproduction

Input header:

#include <stdint.h>

typedef struct {
  void *ptr;
} Context;

void processWithBounds(Context ctx, int64_t bounds[4]);

Command:

bindgen --header bug2-array-parameter.h --package test.native --link-name test --llvm-bin $LLVM_BIN_PATH --c --flavour scala-native05 --c-import "bug2-array-parameter.h" --clang-include .

Generated output (invalid):

void __sn_wrap_test_native_processWithBounds(Context *ctx, int64_t[4] bounds) {
  processWithBounds(*ctx, bounds);
};

Expected output (valid C):

void __sn_wrap_test_native_processWithBounds(Context *ctx, int64_t bounds[4]) {
  processWithBounds(*ctx, bounds);
}

Or equivalently (since arrays decay to pointers in function parameters):

void __sn_wrap_test_native_processWithBounds(Context *ctx, int64_t *bounds) {
  processWithBounds(*ctx, bounds);
}

Compiler Error

error: expected ')'
void __sn_wrap_test_native_processWithBounds(Context *ctx, int64_t[4] bounds)
   ^

Analysis

In C, array parameter declarations require the parameter name before the size specifier:

  • Invalid: int64_t[4] bounds
  • Valid: int64_t bounds[4] or int64_t *bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions