github.com/shijuvar/go@v0.0.0-20141209052335-e8f13700b70c/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 returns the size in bytes occupied by the value v.  The size is that of the
    28  // "top level" of the value only.  For instance, if v is a slice, it returns the size of
    29  // the slice descriptor, not the size of the memory referenced by the slice.
    30  func Sizeof(v ArbitraryType) uintptr
    31  
    32  // Offsetof returns the offset within the struct of the field represented by v,
    33  // which must be of the form structValue.field.  In other words, it returns the
    34  // number of bytes between the start of the struct and the start of the field.
    35  func Offsetof(v ArbitraryType) uintptr
    36  
    37  // Alignof returns the alignment of the value v.  It is the maximum value m such
    38  // that the address of a variable with the type of v will always be zero mod m.
    39  // If v is of the form structValue.field, it returns the alignment of field f within struct object obj.
    40  func Alignof(v ArbitraryType) uintptr