Golang error (Slice of unaddressable value)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The process of converting the generated MD5 to string using Golang has the following compilation error:

Error Resolution:

It is important to note that the Func Sum (data []byte) [Size]byte] Returns the result of the array instead of the slice (slice).

The following example shows that the compiler error line is because [3]int{1,2,3} is not assigned to any variable, the compiler does not know its address, so compiling to [:] will cause an error. The workaround is to assign [3]int{1,2,3} to a variable and then slice the variable.

dill$ Go run test.go# command-line-arguments./test.go:5: -: Invalid operation [3]intliteral[:] (slice of unaddressable value)dill$ cat Test.gopackage mainimport"FMT"Func Main () {b:= [3]int{1,2,3}[:]//Compile Error//B: = [3]int{1,2,3}//Worksc: = b[:]//WorksFmt. Println (c[0])}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.