c-for-go
c-for-go copied to clipboard
typedef of user-defined enum in C header file causes syntax error in types.go
While working with c-for-go, I've encountered the following issue.
Suppose you have a header file that looks something like this:
// example.h
typedef enum my_type {
FOO = 1,
BAR = 2,
} my_type;
typedef enum my_type my_aliased_type;
and an example.yml configuration file:
---
GENERATOR:
PackageName: example
PackageDescription: "Package example shows an issue in c-for-go"
Includes:
- example/example.h
PARSER:
IncludePaths:
- example/
SourcesPaths:
- example/example.h
TRANSLATOR:
Rules:
global:
- {action: accept}
- {load: snakecase}
When I run c-for-go, I get the following error:
$ c-for-go example.yml
processing example.yml ⠋[WARN] cannot gofmt example/types.go: example/types.go:16:22: expected type, found newline (and 1 more errors)
processing example.yml done.
The generated example/types.go file looks like this:
// WARNING: This file has automatically been generated on Thu, 13 Jun 2019 13:25:38 EDT.
// Code generated by https://git.io/c-for-go. DO NOT EDIT.
package example
/*
#include "example/example.h"
#include <stdlib.h>
#include "cgo_helpers.h"
*/
import "C"
// myAliasedType as declared in example/example.h:6
type myAliasedType
Where I would expect line 16 to look like this:
type myAliasedType myType
I'm aware there may be some uncertainty in how to define the constants for the aliased type, since Go will not allow implicit type conversion here, whereas C would.
Closing since no response.
Sorry, just missed that issue. Probably a renaming scheme would help avoiding a missing type name, but that will still require a type cast.
However, a type cast requirement can be avoided by introducing Go aliases and adding that feature into c-for-go. I expect this issue might be a good starting point for such improvement.
I'm facing this same issue