Include a file: Difference between revisions

Added Go
(Removed {{omit from/Go}})
(Added Go)
Line 741:
The inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries.
<lang visualfoxpro>#include "inkey.ch"</lang>
 
=={{header|Go}}==
Go has a 'package' system and doesn't therefore need to include source code from other files via an #include directive (as found in C/C++) or similar.
 
Instead one can simply give the other source code file(s) the same package name as the 'main' file, copy them to the same directory and build them all together. For example:
<lang go>// main.go
package main
 
import "fmt"
 
func hello() {
fmt.Println("Hello from main.go")
}
 
func main() {
hello()
hello2()
}</lang>
 
<lang go>// main2.go
package main
 
import "fmt"
 
func hello2() {
fmt.Println("Hello from main2.go")
}</lang>
 
{{out}}
<pre>
$ go build main.go main2.go
$ ./main
Hello from main.go
Hello from main2.go
</pre>
 
=={{header|Haskell}}==
9,490

edits