You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the tail of the (open) CL 242018 for the (approved) proposal #29982. There are a number of use cases where bits, not bytes as unsafe.Sizeof and sizeof.Xxx speak in, are really useful and it is a shame that you have to manually derive them, const UintBits = sizeof.Uint * 8, as this is error prone. Instead we should expose constants for bit sizes too:
package sizeof
const (
bitsSize=size*8// 32 or 64BitsBool=8BitsByte=Uint8BitsComplex64=64BitsComplex128=128BitsFloat32=32BitsFloat64=64BitsInt=bitsSizeBitsUint8=8BitsInt16=16BitsInt32=32BitsInt64=64BitsRune=BitsInt32BitsUint=bitSizeBitsUint8=8BitsUint16=16BitsUint32=32BitsUint64=64BitsUintptr=bitSize
)
We could derive BitsXxx from Xxx * 8, but the current format seems more terse and intuitive. As well, the names could use a suffix, XxxBits, instead of the current prefix, since we get custom ordering for blocked constants, but to me, prefixes displays better and follows other standard library conventions: http.StatusXxx and xxx.ErrYyy.
Depending on the use case, we could instead export a constant or function for deriving these values. While the former is still prone to user error, it should be intuitive for users familiar with time.Duration. The latter seems like a blocker because functions cannot be compile time constant:
// Bits stores the number of bits in a byte.//// This is useful for converting byte type sizes into bits:// const UintBits = sizeof.Uint * sizeof.BitsconstBits=8
// Bits converts byte sizes into bits.//// This is useful for converting byte type sizes into bits:// var UintBits = sizeof.Bits(sizeof.Uint)funcBits(bytesint) int { returnbytes*8 }
The text was updated successfully, but these errors were encountered:
See the tail of the (open) CL 242018 for the (approved) proposal #29982. There are a number of use cases where bits, not bytes as
unsafe.Sizeof
andsizeof.Xxx
speak in, are really useful and it is a shame that you have to manually derive them,const UintBits = sizeof.Uint * 8
, as this is error prone. Instead we should expose constants for bit sizes too:We could derive
BitsXxx
fromXxx * 8
, but the current format seems more terse and intuitive. As well, the names could use a suffix,XxxBits
, instead of the current prefix, since we get custom ordering for blocked constants, but to me, prefixes displays better and follows other standard library conventions:http.StatusXxx
andxxx.ErrYyy
.Depending on the use case, we could instead export a constant or function for deriving these values. While the former is still prone to user error, it should be intuitive for users familiar with
time.Duration
. The latter seems like a blocker because functions cannot be compile time constant:The text was updated successfully, but these errors were encountered: