On Thu, Dec 7, 2017 at 4:53 AM, <asaav...@gmail.com> wrote: > > I am working on a pilot go/cgo project for a database driver. For one of my > C functions called by go, I chose a generic, unfortunate name connect(). My > program kept dumping core on Linux. I did some tracing and found out that > my function connect() was being called twice even though I called it just > once. I renamed the function as myconnect() and the problem went away. > Here is an nm output after the fact: > > 0000000000000277 T _cgo_c208fc38ae96_Cfunc_myconnect > 0000000000000634 T myconnect > > Is this expected? Is there a general pattern to protect against this?
This is a general problem with C, that Go avoids by using packages and C++ avoids by using namespaces. C has a single flat namespace for all functions, and if you accidentally reuse an existing function name your program will behave strangely. The general pattern to protect against this is to use static functions whenever possible, and to use a unique prefix for all globally visible functions. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.