FAQ
i have a very interesting question normaly in hash package . in Hash
interface . the sum methode append the current hash to the slice of bytes
giving in the paramettre . so when i do h.sum([]byte("")) it will append
[]byte("") to hash(byte) . but when i do

h.sum(nil) it work !!!!!!!!! .normaly it's like doing
append(nil,[]byte("current hash")) normally it shouldn't work

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Dave Cheney at Sep 23, 2015 at 12:42 am
    Please show some code that demonstrates the problem you are seeing.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • WALID BELRHALMIA at Sep 23, 2015 at 12:55 am

    look:

    package main
    import (
    "crypto/md5"
    "fmt"
    "io")

    func main() {
    h := md5.New()
    io.WriteString(h, "The fog is getting thicker!")
    fmt.Printf("%x", h.Sum(nil))}
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Bardin at Sep 23, 2015 at 12:57 am

    On Tuesday, September 22, 2015 at 8:25:48 PM UTC-4, WALID BELRHALMIA wrote:
    i have a very interesting question normaly in hash package . in Hash
    interface . the sum methode append the current hash to the slice of bytes
    giving in the paramettre . so when i do h.sum([]byte("")) it will append
    []byte("") to hash(byte) . but when i do

    h.sum(nil) it work !!!!!!!!! .normaly it's like doing
    append(nil,[]byte("current hash")) normally it shouldn't work
    That only doesn't work, because it's not valid go

    If you use the correct type as the first argument to append, and the
    correct syntax for the second, yes you can append to a nil slice

    http://play.golang.org/p/DaTXvJw54w

    func main() {
    b := append([]byte(nil), []byte("current hash")...)
    fmt.Println(string(b))
    }

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Nigel Tao at Sep 23, 2015 at 12:59 am

    On Wed, Sep 23, 2015 at 10:25 AM, WALID BELRHALMIA wrote:
    h.sum(nil) it work !!!!!!!!!
    A nil slice is a valid, empty slice. It has length 0, you can range
    over it (0 times), you can append to it, etc.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 23, '15 at 12:25a
activeSep 23, '15 at 12:59a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase