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 comment unreasonable #14098

Closed
iexploree opened this issue Jan 26, 2016 · 4 comments
Closed

cmd/cgo: cgo comment unreasonable #14098

iexploree opened this issue Jan 26, 2016 · 4 comments

Comments

@iexploree
Copy link

package main

/**
#include <stdio.h>
void hello() {
    printf("Hello world.\n");
}
*/
import "C"

func main() {
    C.hello()
}

The program compile error as below. It take me 15 minutes to repare it - replace '/**' with '/*'. It let me down when i fixed the problem.
i think it is bug.

# command-line-arguments
In file included from /usr/include/stdio.h:33:0,
                 from ./comment.go:4:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h:212:1: error: expected identifier or '(' before 'typedef'
 typedef __SIZE_TYPE__ size_t;
 ^
In file included from /usr/include/stdio.h:74:0,
                 from ./comment.go:4:
/usr/include/libio.h:306:3: error: unknown type name 'size_t'
   size_t __pad5;
   ^
/usr/include/libio.h:310:67: error: 'size_t' undeclared here (not in a function)
   char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
                                                                   ^
/usr/include/libio.h:338:62: error: expected declaration specifiers or '...' before 'size_t'
 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
                                                              ^
/usr/include/libio.h:347:6: error: expected declaration specifiers or '...' before 'size_t'
      size_t __n);
      ^
/usr/include/libio.h:469:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
 extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t);
                   ^
In file included from ./comment.go:4:0:
/usr/include/stdio.h:319:35: error: expected declaration specifiers or '...' before 'size_t'
 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
                                   ^
/usr/include/stdio.h:325:47: error: expected declaration specifiers or '...' before 'size_t'
 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
                                               ^
/usr/include/stdio.h:337:20: error: expected declaration specifiers or '...' before 'size_t'
       int __modes, size_t __n) __THROW;
                    ^
/usr/include/stdio.h:344:10: error: expected declaration specifiers or '...' before 'size_t'
          size_t __size) __THROW;
          ^
/usr/include/stdio.h:386:44: error: expected declaration specifiers or '...' before 'size_t'
 extern int snprintf (char *__restrict __s, size_t __maxlen,
                                            ^
/usr/include/stdio.h:390:45: error: expected declaration specifiers or '...' before 'size_t'
 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
                                             ^
/usr/include/stdio.h:666:11: error: expected declaration specifiers or '...' before 'size_t'
           size_t *__restrict __n, int __delimiter,
           ^
/usr/include/stdio.h:669:9: error: expected declaration specifiers or '...' before 'size_t'
         size_t *__restrict __n, int __delimiter,
         ^
/usr/include/stdio.h:679:8: error: expected declaration specifiers or '...' before 'size_t'
        size_t *__restrict __n,
        ^
/usr/include/stdio.h:709:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
 extern size_t fread (void *__restrict __ptr, size_t __size,
               ^
/usr/include/stdio.h:715:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
 extern size_t fwrite (const void *__restrict __ptr, size_t __size,
               ^
/usr/include/stdio.h:737:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
               ^
/usr/include/stdio.h:739:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'
 extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
               ^
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jan 26, 2016
@ianlancetaylor
Copy link
Contributor

Do you have a suggestion for what we can change?

I don't think just looking for * at the beginning of the import "C" comment makes much sense. While it would be nice to do a better job on the C comment in general, I don't think that specific problem is common.

@iexploree
Copy link
Author

I don't think it's a good idea to put c code into c comment block. It's better using like ''' '''' as c code block. But it can't be changed now. The comment as below will works fine, I hope. Because the java/js programmer using the style frequently( and the comment is legal in c/c++/go), so I guess most people will suffer the problem.

/****
*/

@ianlancetaylor ianlancetaylor changed the title cgo comment unreasonable cmd/cgo: cgo comment unreasonable Jan 26, 2016
@ianlancetaylor
Copy link
Contributor

Thanks for the comment, but you haven't made a suggestion for what we can change.

@josharian
Copy link
Contributor

Timed out; closing. Please comment if you have suggestions for what to change, and I'll reopen.

@golang golang locked and limited conversation to collaborators Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants