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

Comments

@nathan-fiscaletti
Copy link
Contributor

@nathan-fiscaletti nathan-fiscaletti commented Mar 6, 2020

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 this to the Backlog milestone Mar 6, 2020
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 6, 2020

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 6, 2020

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

This comment has been minimized.

Copy link
Contributor Author

@nathan-fiscaletti nathan-fiscaletti commented Mar 6, 2020

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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 7, 2020

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
@gopherbot gopherbot closed this in a7f918c Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.