Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
becki:linux:golang [2011-07-25 22:08] becki |
becki:linux:golang [2018-02-26 11:24] (aktuell) becki |
||
|---|---|---|---|
| Zeile 30: | Zeile 30: | ||
| * export GOHOSTARCH=arm, export GOHOSTOS=linux, export GOARCH=arm, export GOOS=linux may be necessary too | * export GOHOSTARCH=arm, export GOHOSTOS=linux, export GOARCH=arm, export GOOS=linux may be necessary too | ||
| - | ==== Crosscompiling on x86 for ARM5 == | + | ==== Build Crosscompiler on x86 for ARM5 == |
| + | |||
| + | Export the following variables before running ''src/all.bash'': | ||
| <code bash> | <code bash> | ||
| + | export GOROOT=$(pwd) | ||
| export GOHOSTARCH=386 | export GOHOSTARCH=386 | ||
| export GOHOSTOS=linux | export GOHOSTOS=linux | ||
| Zeile 39: | Zeile 42: | ||
| export GOARM=5 | export GOARM=5 | ||
| </code> | </code> | ||
| + | |||
| ===== Hello World == | ===== Hello World == | ||
| Zeile 138: | Zeile 142: | ||
| * Arrays are copied by value :!: | * Arrays are copied by value :!: | ||
| * A Pointer to an array is possible (unlike in C where the pointer represents the array) | * A Pointer to an array is possible (unlike in C where the pointer represents the array) | ||
| + | |||
| </note> | </note> | ||
| Zeile 185: | Zeile 190: | ||
| <note tip> | <note tip> | ||
| - | |||
| * Slices are copied //by value// but the internal arrays are copied //by reference// :!: | * Slices are copied //by value// but the internal arrays are copied //by reference// :!: | ||
| * Slices have a length (number of items) and a capacity (length of underlying array(?)) | * Slices have a length (number of items) and a capacity (length of underlying array(?)) | ||
| + | |||
| </note> | </note> | ||
| <note important>Appending to a Slice results in a new slice. The new slice may point to a different array than the original slice.</note> | <note important>Appending to a Slice results in a new slice. The new slice may point to a different array than the original slice.</note> | ||
| Zeile 255: | Zeile 260: | ||
| * In order to really work on the object, the receiver of the method must be a //pointer// to the object, otherwise the method operates ony on an (anonymous) copy. | * In order to really work on the object, the receiver of the method must be a //pointer// to the object, otherwise the method operates ony on an (anonymous) copy. | ||
| * Invoking methods on //pointers to objects// has the same syntax and work the same as invoking the method directly on the object. | * Invoking methods on //pointers to objects// has the same syntax and work the same as invoking the method directly on the object. | ||
| + | |||
| </note> | </note> | ||
| Zeile 318: | Zeile 324: | ||
| * Implement the methods of the interface with an object //pointer// as receiver | * Implement the methods of the interface with an object //pointer// as receiver | ||
| * Instantiate the interface with the //adress// of the object | * Instantiate the interface with the //adress// of the object | ||
| + | |||
| </note> | </note> | ||
| <note important>Some :?: library functions which return an interface in reality return a pointer to an implementation of the interface (see e.g. [[golang>pkg/net/#Listener.Listen|net.Listen]])</note> | <note important>Some :?: library functions which return an interface in reality return a pointer to an implementation of the interface (see e.g. [[golang>pkg/net/#Listener.Listen|net.Listen]])</note> | ||
| Zeile 323: | Zeile 330: | ||
| ===== Handling Errors == | ===== Handling Errors == | ||
| - | Defer, Panic, Recover: http://blog.golang.org/2010_08_01_archive.html => The convention in the Go libraries is that even when a package uses panic internally, its external API still returns explicit ''os.Error'' values. | + | Defer, Panic, Recover: http://blog.golang.org/2010_08_01_archive.html ⇒ The convention in the Go libraries is that even when a package uses panic internally, its external API still returns explicit ''os.Error'' values. |
| [[golang>pkg/os/#Error|os.Error]] is the same interface as [[golang>pkg/fmt/#Stringer|fmt.Stringer]], i.e. it has a method called ''String()'' wich returns a ''string''. Thus an instance of os.Error can always be passed to the functions in ''fmt'' and ''log'' directly, without explicitely calling the ''String()'' method. E.g: | [[golang>pkg/os/#Error|os.Error]] is the same interface as [[golang>pkg/fmt/#Stringer|fmt.Stringer]], i.e. it has a method called ''String()'' wich returns a ''string''. Thus an instance of os.Error can always be passed to the functions in ''fmt'' and ''log'' directly, without explicitely calling the ''String()'' method. E.g: | ||