Home > Article > Backend Development > What do slashes and dots signify in Go's function names and prototypes?
Slashes and Dots in Function Names and Prototypes
Question:
In Go's source code, we encounter function names and prototypes with slashes and dots. What do these symbols signify, and are they valid C constructs?
Answer:
Middot (·)
The middot character (·) is an extension in Go's internal C compiler, which originates from the Plan 9 C compiler. In this context, it serves as a namespace separator.
Example:
The following code demonstrates the use of the middot:
<code class="c">void ·Bar1() {} void foo·bar2() {} void foo∕baz·bar3() {}</code>
The internal C compiler produces the following symbols:
T "".Bar1 T foo.bar2 T foo∕baz.bar3
Slash (/)
The slash (/) is used to separate namespaces in import statements.
Example:
In the following import statement, the empty namespace "" is substituted with the package path:
<code class="go">import examp "path/to/package/example"</code>
Implications for Go Code
The middot character allows developers to export functions with Go-like naming conventions to C code. For instance, by capitalizing the first letter of a function preceded by the middot, it becomes visible to Go code as if it were defined in Go.
Conclusion
The slashes and dots in Go's source code are language extensions that provide flexibility in function naming and enable the interfacing of C and Go code. However, it's important to note that these constructs are not standard C syntax.
The above is the detailed content of What do slashes and dots signify in Go's function names and prototypes?. For more information, please follow other related articles on the PHP Chinese website!