github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/src/unsafe/unsafe.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  	Package unsafe contains operations that step around the type safety of Go programs.
     7  
     8  	Packages that import unsafe may be non-portable and are not protected by the
     9  	Go 1 compatibility guidelines.
    10  */
    11  package unsafe
    12  
    13  // ArbitraryType is here for the purposes of documentation only and is not actually
    14  // part of the unsafe package.  It represents the type of an arbitrary Go expression.
    15  type ArbitraryType int
    16  
    17  // Pointer represents a pointer to an arbitrary type.  There are four special operations
    18  // available for type Pointer that are not available for other types.
    19  //	1) A pointer value of any type can be converted to a Pointer.
    20  //	2) A Pointer can be converted to a pointer value of any type.
    21  //	3) A uintptr can be converted to a Pointer.
    22  //	4) A Pointer can be converted to a uintptr.
    23  // Pointer therefore allows a program to defeat the type system and read and write
    24  // arbitrary memory. It should be used with extreme care.
    25  type Pointer *ArbitraryType
    26  
    27  // Sizeof takes an expression x of any type and returns the size in bytes
    28  // of a hypothetical variable v as if v was declared via var v = x.
    29  // The size does not include any memory possibly referenced by x.
    30  // For instance, if x is a slice,  Sizeof returns the size of the slice
    31  // descriptor, not the size of the memory referenced by the slice.
    32  func Sizeof(x ArbitraryType) uintptr
    33  
    34  // Offsetof returns the offset within the struct of the field represented by x,
    35  // which must be of the form structValue.field.  In other words, it returns the
    36  // number of bytes between the start of the struct and the start of the field.
    37  func Offsetof(x ArbitraryType) uintptr
    38  
    39  // Alignof takes an expression x of any type and returns the alignment
    40  // of a hypothetical variable v as if v was declared via var v = x.
    41  // It is the largest value m such that the address of v is zero mod m.
    42  func Alignof(x ArbitraryType) uintptr