Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: CGo Exported Function has an empty line between it and its documentation block #37722

Closed
nathan-fiscaletti opened this issue Mar 6, 2020 · 4 comments · Fixed by sthagen/golang-go#198
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@nathan-fiscaletti
Copy link
Contributor

I'm writing a library in Go that I'm compiling to a native library using CGo, however when the functions are exported they have this annoying empty line between the function declaration and the documentation comment.

As an example, let's say I have this in my go file

/**
 * Prints an integer.
 *
 * @param p0 an integer to print.
 */
//export PrintInteger
func PrintInteger(val C.int) {
    fmt.Printf("%v", val);
}

Once it's exported in my C header file, it looks like this

/**
 * Prints an integer.
 *
 * @param p0 an integer to print.
 */

extern void PrintInteger(int p0);

That empty line for the most part isn't a problem, but on some IDEs when parsing that header file they have difficulty properly displaying the intellisense, making consumption of the header slightly more difficult. Especially when you factor in the way that cgo renames function parameters

I've found what i believe is the area in the go source code that causes this:

https://github.com/golang/go/blob/master/src/cmd/cgo/out.go#L922

if len(exp.Doc) > 0 {
    fmt.Fprintf(fgcch, "\n%s", exp.Doc)
}
fmt.Fprintf(fgcch, "\nextern %s;\n", s)

I feel like perhaps that \n before the extern keyword shouldn't be there. Unless this is intentional?

@ianlancetaylor ianlancetaylor changed the title CGo Exported Function has an empty line between it and it's documentation block cmd/cgo: CGo Exported Function has an empty line between it and it's documentation block Mar 6, 2020
@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Mar 6, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Mar 6, 2020
@ianlancetaylor
Copy link
Contributor

Seems like the newline before the doc comment shouldn't affect this.

@ianlancetaylor
Copy link
Contributor

Sorry, misunderstood.

I'm surprised this makes a difference in a C header file. Do editors expect there to be no blank line between C docs and C declarations?

@nathan-fiscaletti
Copy link
Contributor Author

It's certainly an issue when using Android Studio (where i tend to do most of my work). The same header file works fine in XCode (the other IDE i use), and in Visual Studio Code. So far i've only run into the issue in Android Studio, but it seems like a pretty stupid problem to have.

@gopherbot
Copy link

Change https://golang.org/cl/222419 mentions this issue: cmd/cgo: removes new line for exported functions

@nathan-fiscaletti nathan-fiscaletti changed the title cmd/cgo: CGo Exported Function has an empty line between it and it's documentation block cmd/cgo: CGo Exported Function has an empty line between it and its documentation block Mar 7, 2020
@golang golang locked and limited conversation to collaborators Mar 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
3 participants