Returns the field name of a struct, union, or enum.
The result is a compile time constant.
It does not include functions, variables, or constants.
@memberType(comptime T: type, comptime index: usize) type
Returns the field type of a struct or union.
@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize)
This function copies bytes from one region of memory to another. dest
and
source
are both pointers and must not overlap.
This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this:
for (source[0...byte_count]) |b, i| dest[i] = b;
The optimizer is intelligent enough to turn the above snippet into a memcpy.
There is also a standard library function for this:
const mem = @import("std").mem;
mem.copy(u8, dest[0...byte_count], source[0...byte_count]);
@memset(dest: [*]u8, c: u8, byte_count: usize)
This function sets a region of memory to c
. dest
is a pointer.
This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this:
for (dest[0...byte_count]) |*b| b.* = c;
The optimizer is intelligent enough to turn the above snippet into a memset.
There is also a standard library function for this:
const mem = @import("std").mem;
mem.set(u8, dest, c);
@minValue(comptime T: type) comptime_int
This function returns the minimum value of the integer type T.
The result is a compile time constant.
@mod(numerator: T, denominator: T) T
Modulus division. For unsigned integers this is the same as
numerator % denominator
. Caller guarantees denominator > 0
.
@mod(-5, 3) == 1
@divFloor(a, b) + @mod(a, b) == a
For a function that returns an error code, see @import("std").math.mod
.
See also:
@mulWithOverflow(comptime T: type, a: T, b: T, result: *T) bool
Performs result.* = a * b
. If overflow or underflow occurs,
stores the overflowed bits in result
and returns true
.
If no overflow or underflow occurs, returns false
.
@newStackCall(new_stack: []u8, function: var, args: ...) var
This calls a function, in the same way that invoking an expression with parentheses does. However,
instead of using the same stack as the caller, the function uses the stack provided in the new_stack
parameter.
test.zig
const std = @import("std");
const assert = std.debug.assert;
var new_stack_bytes: [1024]u8 = undefined;
test "calling a function with a new stack" {
const arg = 1234;
const a = @newStackCall(new_stack_bytes[0..512], targetFunction, arg);
const b = @newStackCall(new_stack_bytes[512..], targetFunction, arg);
_ = targetFunction(arg);
assert(arg == 1234);
assert(a < b);
}
fn targetFunction(x: i32) usize {
assert(x == 1234);
var local_variable: i32 = 42;
const ptr = &local_variable;
ptr.* += 1;
assert(local_variable == 43);
return @ptrToInt(ptr);
}
$ zig test test.zig
Test 1/1 calling a function with a new stack...OK
All tests passed.
@noInlineCall(function: var, args: ...) var
This calls a function, in the same way that invoking an expression with parentheses does:
test.zig
const assert = @import("std").debug.assert;
test "noinline function call" {
assert(@noInlineCall(add, 3, 9) == 12);
}
fn add(a: i32, b: i32) i32 {
return a + b;
}
$ zig test test.zig
Test 1/1 noinline function call...OK
All tests passed.
Unlike a normal function call, however, @noInlineCall
guarantees that the call
will not be inlined. If the call must be inlined, a compile error is emitted.
See also:
@OpaqueType() type
Creates a new type with an unknown (but non-zero) size and alignment.
This is typically used for type safety when interacting with C code that does not expose struct details. Example:
test.zig
const Derp = @OpaqueType();
const Wat = @OpaqueType();
extern fn bar(d: *Derp) void;
export fn foo(w: *Wat) void {
bar(w);
}
test "call foo" {
foo(undefined);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:6:9: error: expected type '*Derp', found '*Wat'
bar(w);
^
/home/andy/dev/zig/docgen_tmp/test.zig:6:9: note: pointer type child 'Wat' cannot cast into pointer type child 'Derp'
bar(w);
^
@panic(message: []const u8) noreturn
Invokes the panic handler function. By default the panic handler function
calls the public panic
function exposed in the root source file, or
if there is not one specified, invokes the one provided in std/special/panic.zig
.
Generally it is better to use @import("std").debug.panic
.
However, @panic
can be useful for 2 scenarios:
See also:
@popCount(integer: var) var
Counts the number of bits set in an integer.
If integer
is known at comptime, the return type is comptime_int
.
Otherwise, the return type is an unsigned integer with the minimum number
of bits that can represent the bit count of the integer type.
See also:
@ptrCast(comptime DestType: type, value: var) DestType
Converts a pointer of one type to a pointer of another type.
@ptrToInt(value: var) usize
Converts value
to a usize
which is the address of the pointer. value
can be one of these types:
*T
?*T
fn()
?fn()
To convert the other way, use @intToPtr
@rem(numerator: T, denominator: T) T
Remainder division. For unsigned integers this is the same as
numerator % denominator
. Caller guarantees denominator > 0
.
@rem(-5, 3) == -2
@divTrunc(a, b) + @rem(a, b) == a
For a function that returns an error code, see @import("std").math.rem
.
See also:
@returnAddress()
This function returns a pointer to the return address of the current stack frame.
The implications of this are target specific and not consistent across all platforms.
This function is only valid within function scope.
@setAlignStack(comptime alignment: u29)
Ensures that a function will have a stack alignment of at least alignment
bytes.
@setCold(is_cold: bool)
Tells the optimizer that a function is rarely called.
@setRuntimeSafety(safety_on: bool)
Sets whether runtime safety checks are on for the scope that contains the function call.
@setEvalBranchQuota(new_quota: usize)
Changes the maximum number of backwards branches that compile-time code execution can use before giving up and making a compile error.
If the new_quota
is smaller than the default quota (1000
) or
a previously explicitly set quota, it is ignored.
Example:
test.zig
test "foo" {
comptime {
var i = 0;
while (i < 1001) : (i += 1) {}
}
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:4:9: error: evaluation exceeded 1000 backwards branches
while (i < 1001) : (i += 1) {}
^
Now we use @setEvalBranchQuota
:
test.zig
test "foo" {
comptime {
@setEvalBranchQuota(1001);
var i = 0;
while (i < 1001) : (i += 1) {}
}
}
$ zig test test.zig
Test 1/1 foo...OK
All tests passed.
See also:
@setFloatMode(mode: @import("builtin").FloatMode)
Sets the floating point mode of the current scope. Possible values are:
pub const FloatMode = enum {
Strict,
Optimized,
};
Strict
(default) - Floating point operations follow strict IEEE compliance.
Optimized
- Floating point operations may do all of the following:
-ffast-math
in GCC.
The floating point mode is inherited by child scopes, and can be overridden in any scope. You can set the floating point mode in a struct or module scope by using a comptime block.
See also:
@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage)
GlobalLinkage
can be found with @import("builtin").GlobalLinkage
.
See also:
@shlExact(value: T, shift_amt: Log2T) T
Performs the left shift operation (<<
). Caller guarantees
that the shift will not shift any 1 bits out.
The type of shift_amt
is an unsigned integer with log2(T.bit_count)
bits.
This is because shift_amt >= T.bit_count
is undefined behavior.
See also:
@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: *T) bool
Performs result.* = a << b
. If overflow or underflow occurs,
stores the overflowed bits in result
and returns true
.
If no overflow or underflow occurs, returns false
.
The type of shift_amt
is an unsigned integer with log2(T.bit_count)
bits.
This is because shift_amt >= T.bit_count
is undefined behavior.
See also:
@shrExact(value: T, shift_amt: Log2T) T
Performs the right shift operation (>>
). Caller guarantees
that the shift will not shift any 1 bits out.
The type of shift_amt
is an unsigned integer with log2(T.bit_count)
bits.
This is because shift_amt >= T.bit_count
is undefined behavior.
See also:
@sizeOf(comptime T: type) comptime_int
This function returns the number of bytes it takes to store T
in memory.
The result is a target-specific compile time constant.
@sliceToBytes(value: var) []u8
Converts a slice or array to a slice of u8
. The resulting slice has the same
pointer properties as the parameter.
@sqrt(comptime T: type, value: T) T
Performs the square root of a floating point number. Uses a dedicated hardware instruction when available. Currently only supports f32 and f64 at runtime. f128 at runtime is TODO.
This is a low-level intrinsic. Most code can use std.math.sqrt
instead.
@subWithOverflow(comptime T: type, a: T, b: T, result: *T) bool
Performs result.* = a - b
. If overflow or underflow occurs,
stores the overflowed bits in result
and returns true
.
If no overflow or underflow occurs, returns false
.
@tagName(value: var) []const u8
Converts an enum value or union value to a slice of bytes representing the name.
@TagType(T: type) type
For an enum, returns the integer type that is used to store the enumeration value.
For a union, returns the enum type that is used to store the tag value.
@This() type
Returns the innermost struct or union that this function call is inside. This can be useful for an anonymous struct that needs to refer to itself:
test.zig
const std = @import("std");
const assert = std.debug.assert;
test "@This()" {
var items = []i32{ 1, 2, 3, 4 };
const list = List(i32){ .items = items[0..] };
assert(list.length() == 4);
}
fn List(comptime T: type) type {
return struct {
const Self = @This();
items: []T,
fn length(self: Self) usize {
return self.items.len;
}
};
}
$ zig test test.zig
Test 1/1 @This()...OK
All tests passed.
When @This()
is used at global scope, it returns a reference to the
current import. There is a proposal to remove the import type and use an empty struct
type instead. See
#1047 for details.
@truncate(comptime T: type, integer) T
This function truncates bits from an integer type, resulting in a smaller integer type.
The following produces a crash in debug mode and undefined behavior in release mode:
const a: u16 = 0xabcd;
const b: u8 = u8(a);
However this is well defined and working code:
const a: u16 = 0xabcd;
const b: u8 = @truncate(u8, a);
// b is now 0xcd
This function always truncates the significant bits of the integer, regardless of endianness on the target platform.
@typeId(comptime T: type) @import("builtin").TypeId
Returns which kind of type something is. Possible values:
pub const TypeId = enum {
Type,
Void,
Bool,
NoReturn,
Int,
Float,
Pointer,
Array,
Struct,
ComptimeFloat,
ComptimeInt,
Undefined,
Null,
Optional,
ErrorUnion,
Error,
Enum,
Union,
Fn,
Namespace,
Block,
BoundFn,
ArgTuple,
Opaque,
};
@typeInfo(comptime T: type) @import("builtin").TypeInfo
Returns information on the type. Returns a value of the following union:
pub const TypeInfo = union(TypeId) {
Type: void,
Void: void,
Bool: void,
NoReturn: void,
Int: Int,
Float: Float,
Pointer: Pointer,
Array: Array,
Struct: Struct,
ComptimeFloat: void,
ComptimeInt: void,
Undefined: void,
Null: void,
Optional: Optional,
ErrorUnion: ErrorUnion,
ErrorSet: ErrorSet,
Enum: Enum,
Union: Union,
Fn: Fn,
Namespace: void,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
Promise: Promise,
pub const Int = struct {
is_signed: bool,
bits: u8,
};
pub const Float = struct {
bits: u8,
};
pub const Pointer = struct {
size: Size,
is_const: bool,
is_volatile: bool,
alignment: u32,
child: type,
pub const Size = enum {
One,
Many,
Slice,
};
};
pub const Array = struct {
len: usize,
child: type,
};
pub const ContainerLayout = enum {
Auto,
Extern,
Packed,
};
pub const StructField = struct {
name: []const u8,
offset: ?usize,
field_type: type,
};
pub const Struct = struct {
layout: ContainerLayout,
fields: []StructField,
defs: []Definition,
};
pub const Optional = struct {
child: type,
};
pub const ErrorUnion = struct {
error_set: type,
payload: type,
};
pub const Error = struct {
name: []const u8,
value: usize,
};
pub const ErrorSet = struct {
errors: []Error,
};
pub const EnumField = struct {
name: []const u8,
value: usize,
};
pub const Enum = struct {
layout: ContainerLayout,
tag_type: type,
fields: []EnumField,
defs: []Definition,
};
pub const UnionField = struct {
name: []const u8,
enum_field: ?EnumField,
field_type: type,
};
pub const Union = struct {
layout: ContainerLayout,
tag_type: ?type,
fields: []UnionField,
defs: []Definition,
};
pub const CallingConvention = enum {
Unspecified,
C,
Cold,
Naked,
Stdcall,
Async,
};
pub const FnArg = struct {
is_generic: bool,
is_noalias: bool,
arg_type: ?type,
};
pub const Fn = struct {
calling_convention: CallingConvention,
is_generic: bool,
is_var_args: bool,
return_type: ?type,
async_allocator_type: ?type,
args: []FnArg,
};
pub const Promise = struct {
child: ?type,
};
pub const Definition = struct {
name: []const u8,
is_pub: bool,
data: Data,
pub const Data = union(enum) {
Type: type,
Var: type,
Fn: FnDef,
pub const FnDef = struct {
fn_type: type,
inline_type: Inline,
calling_convention: CallingConvention,
is_var_args: bool,
is_extern: bool,
is_export: bool,
lib_name: ?[]const u8,
return_type: type,
arg_names: [][] const u8,
pub const Inline = enum {
Auto,
Always,
Never,
};
};
};
};
};
@typeName(T: type) []u8
This function returns the string representation of a type.
@typeOf(expression) type
This function returns a compile-time constant, which is the type of the expression passed as an argument. The expression is evaluated.
Zig has four build modes:
To add standard build options to a build.zig
file:
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const exe = b.addExecutable("example", "example.zig");
exe.setBuildMode(b.standardReleaseOptions());
b.default_step.dependOn(&exe.step);
}
This causes these options to be available:
-Drelease-safe=[bool] optimizations on and safety on
-Drelease-fast=[bool] optimizations on and safety off
-Drelease-small=[bool] size optimizations on and safety off
$ zig build-exe example.zig
$ zig build-exe example.zig --release-fast
$ zig build-exe example.zig --release-safe
$ zig build-exe example.zig --release-small
See also:
Zig has many instances of undefined behavior. If undefined behavior is detected at compile-time, Zig emits a compile error and refuses to continue. Most undefined behavior that cannot be detected at compile-time can be detected at runtime. In these cases, Zig has safety checks. Safety checks can be disabled on a per-block basis with setRuntimeSafety. The ReleaseFast build mode disables all safety checks in order to facilitate optimizations.
When a safety check fails, Zig crashes with a stack trace, like this:
test.zig
test "safety check" {
unreachable;
}
$ zig test test.zig
Test 1/1 safety check...reached unreachable code
/home/andy/dev/zig/docgen_tmp/test.zig:2:5: 0x205054 in ??? (test)
unreachable;
^
/home/andy/dev/zig/build/lib/zig/std/special/test_runner.zig:13:25: 0x22294a in ??? (test)
if (test_fn.func()) |_| {
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:96:22: 0x2226fb in ??? (test)
root.main() catch |err| {
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222675 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224d8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222390 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
Tests failed. Use the following command to reproduce the failure:
/home/andy/dev/zig/docgen_tmp/test
At compile-time:
test.zig
comptime {
assert(false);
}
fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:5:14: error: unable to evaluate constant expression
if (!ok) unreachable; // assertion failure
^
/home/andy/dev/zig/docgen_tmp/test.zig:2:11: note: called from here
assert(false);
^
/home/andy/dev/zig/docgen_tmp/test.zig:1:10: note: called from here
comptime {
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
std.debug.assert(false);
}
$ zig build-exe test.zig
$ ./test
reached unreachable code
/home/andy/dev/zig/build/lib/zig/std/debug/index.zig:120:13: 0x205029 in ??? (test)
unreachable; // assertion failure
^
/home/andy/dev/zig/docgen_tmp/test.zig:4:21: 0x2226cb in ??? (test)
std.debug.assert(false);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const array = "hello";
const garbage = array[5];
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:26: error: index 5 outside array of size 5
const garbage = array[5];
^
At runtime:
test.zig
pub fn main() void {
var x = foo("hello");
}
fn foo(x: []const u8) u8 {
return x[5];
}
$ zig build-exe test.zig
$ ./test
index out of bounds
/home/andy/dev/zig/docgen_tmp/test.zig:6:13: 0x222709 in ??? (test)
return x[5];
^
/home/andy/dev/zig/docgen_tmp/test.zig:2:16: 0x2226d4 in ??? (test)
var x = foo("hello");
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const value: i32 = -1;
const unsigned = @intCast(u32, value);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:22: error: attempt to cast negative value to unsigned integer
const unsigned = @intCast(u32, value);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var value: i32 = -1;
var unsigned = @intCast(u32, value);
std.debug.warn("value: {}\n", unsigned);
}
$ zig build-exe test.zig
$ ./test
attempt to cast negative value to unsigned integer
/home/andy/dev/zig/docgen_tmp/test.zig:5:20: 0x2226fe in ??? (test)
var unsigned = @intCast(u32, value);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
To obtain the maximum value of an unsigned integer, use @maxValue.
At compile-time:
test.zig
comptime {
const spartan_count: u16 = 300;
const byte = @intCast(u8, spartan_count);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
const byte = @intCast(u8, spartan_count);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var spartan_count: u16 = 300;
const byte = @intCast(u8, spartan_count);
std.debug.warn("value: {}\n", byte);
}
$ zig build-exe test.zig
$ ./test
integer cast truncated bits
/home/andy/dev/zig/docgen_tmp/test.zig:5:18: 0x222707 in ??? (test)
const byte = @intCast(u8, spartan_count);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
To truncate bits, use @truncate.
The following operators can cause integer overflow:
+
(addition)-
(subtraction)-
(negation)*
(multiplication)/
(division)Example with addition at compile-time:
test.zig
comptime {
var byte: u8 = 255;
byte += 1;
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:10: error: operation caused overflow
byte += 1;
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var byte: u8 = 255;
byte += 1;
std.debug.warn("value: {}\n", byte);
}
$ zig build-exe test.zig
$ ./test
integer overflow
/home/andy/dev/zig/docgen_tmp/test.zig:5:10: 0x2226ee in ??? (test)
byte += 1;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
These functions provided by the standard library return possible errors.
@import("std").math.add
@import("std").math.sub
@import("std").math.mul
@import("std").math.divTrunc
@import("std").math.divFloor
@import("std").math.divExact
@import("std").math.shl
Example of catching an overflow for addition:
test.zig
const math = @import("std").math;
const warn = @import("std").debug.warn;
pub fn main() !void {
var byte: u8 = 255;
byte = if (math.add(u8, byte, 1)) |result| result else |err| {
warn("unable to add one: {}\n", @errorName(err));
return err;
};
warn("result: {}\n", byte);
}
$ zig build-exe test.zig
$ ./test
unable to add one: Overflow
error: Overflow
/home/andy/dev/zig/build/lib/zig/std/math/index.zig:252:5: 0x2229fa in ??? (test)
return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer;
^
/home/andy/dev/zig/docgen_tmp/test.zig:8:9: 0x222858 in ??? (test)
return err;
^
These builtins return a bool
of whether or not overflow
occurred, as well as returning the overflowed bits:
Example of @addWithOverflow:
test.zig
const warn = @import("std").debug.warn;
pub fn main() void {
var byte: u8 = 255;
var result: u8 = undefined;
if (@addWithOverflow(u8, byte, 10, &result)) {
warn("overflowed result: {}\n", result);
} else {
warn("result: {}\n", result);
}
}
$ zig build-exe test.zig
$ ./test
overflowed result: 9
These operations have guaranteed wraparound semantics.
+%
(wraparound addition)-%
(wraparound subtraction)-%
(wraparound negation)*%
(wraparound multiplication)test.zig
const assert = @import("std").debug.assert;
test "wraparound addition and subtraction" {
const x: i32 = @maxValue(i32);
const min_val = x +% 1;
assert(min_val == @minValue(i32));
const max_val = min_val -% 1;
assert(max_val == @maxValue(i32));
}
$ zig test test.zig
Test 1/1 wraparound addition and subtraction...OK
All tests passed.
At compile-time:
test.zig
comptime {
const x = @shlExact(u8(0b01010101), 2);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:2:15: error: operation caused overflow
const x = @shlExact(u8(0b01010101), 2);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var x: u8 = 0b01010101;
var y = @shlExact(x, 2);
std.debug.warn("value: {}\n", y);
}
$ zig build-exe test.zig
$ ./test
left shift overflowed bits
/home/andy/dev/zig/docgen_tmp/test.zig:5:13: 0x222705 in ??? (test)
var y = @shlExact(x, 2);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const x = @shrExact(u8(0b10101010), 2);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:2:15: error: exact shift shifted out 1 bits
const x = @shrExact(u8(0b10101010), 2);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var x: u8 = 0b10101010;
var y = @shrExact(x, 2);
std.debug.warn("value: {}\n", y);
}
$ zig build-exe test.zig
$ ./test
right shift overflowed bits
/home/andy/dev/zig/docgen_tmp/test.zig:5:13: 0x222705 in ??? (test)
var y = @shrExact(x, 2);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const a: i32 = 1;
const b: i32 = 0;
const c = a / b;
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:4:17: error: division by zero
const c = a / b;
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var a: u32 = 1;
var b: u32 = 0;
var c = a / b;
std.debug.warn("value: {}\n", c);
}
$ zig build-exe test.zig
$ ./test
division by zero
/home/andy/dev/zig/docgen_tmp/test.zig:6:15: 0x222712 in ??? (test)
var c = a / b;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const a: i32 = 10;
const b: i32 = 0;
const c = a % b;
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:4:17: error: division by zero
const c = a % b;
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var a: u32 = 10;
var b: u32 = 0;
var c = a % b;
std.debug.warn("value: {}\n", c);
}
$ zig build-exe test.zig
$ ./test
remainder division by zero or negative value
/home/andy/dev/zig/docgen_tmp/test.zig:6:15: 0x222712 in ??? (test)
var c = a % b;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const a: u32 = 10;
const b: u32 = 3;
const c = @divExact(a, b);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:4:15: error: exact division had a remainder
const c = @divExact(a, b);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var a: u32 = 10;
var b: u32 = 3;
var c = @divExact(a, b);
std.debug.warn("value: {}\n", c);
}
$ zig build-exe test.zig
$ ./test
exact division produced remainder
/home/andy/dev/zig/docgen_tmp/test.zig:6:13: 0x222733 in ??? (test)
var c = @divExact(a, b);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
var bytes = [5]u8{ 1, 2, 3, 4, 5 };
var slice = @bytesToSlice(u32, bytes);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:17: error: unable to convert [5]u8 to []align(1) const u32: size mismatch
var slice = @bytesToSlice(u32, bytes);
^
/home/andy/dev/zig/docgen_tmp/test.zig:3:31: note: u32 has size 4; remaining bytes: 1
var slice = @bytesToSlice(u32, bytes);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var bytes = [5]u8{ 1, 2, 3, 4, 5 };
var slice = @bytesToSlice(u32, bytes[0..]);
std.debug.warn("value: {}\n", slice[0]);
}
$ zig build-exe test.zig
$ ./test
slice widening size mismatch
/home/andy/dev/zig/docgen_tmp/test.zig:5:17: 0x222756 in ??? (test)
var slice = @bytesToSlice(u32, bytes[0..]);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const optional_number: ?i32 = null;
const number = optional_number.?;
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:35: error: unable to unwrap null
const number = optional_number.?;
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var optional_number: ?i32 = null;
var number = optional_number.?;
std.debug.warn("value: {}\n", number);
}
$ zig build-exe test.zig
$ ./test
attempt to unwrap null
/home/andy/dev/zig/docgen_tmp/test.zig:5:33: 0x2226ff in ??? (test)
var number = optional_number.?;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
One way to avoid this crash is to test for null instead of assuming non-null, with
the if
expression:
test.zig
const warn = @import("std").debug.warn;
pub fn main() void {
const optional_number: ?i32 = null;
if (optional_number) |number| {
warn("got number: {}\n", number);
} else {
warn("it's null\n");
}
}
$ zig build-exe test.zig
$ ./test
it's null
See also:
At compile-time:
test.zig
comptime {
const number = getNumberOrFail() catch unreachable;
}
fn getNumberOrFail() !i32 {
return error.UnableToReturnNumber;
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:2:38: error: caught unexpected error 'UnableToReturnNumber'
const number = getNumberOrFail() catch unreachable;
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
const number = getNumberOrFail() catch unreachable;
std.debug.warn("value: {}\n", number);
}
fn getNumberOrFail() !i32 {
return error.UnableToReturnNumber;
}
$ zig build-exe test.zig
$ ./test
attempt to unwrap error: UnableToReturnNumber
/home/andy/dev/zig/docgen_tmp/test.zig:9:5: 0x22276b in ??? (test)
return error.UnableToReturnNumber;
^
???:?:?: 0x21fa3e in ??? (???)
/home/andy/dev/zig/docgen_tmp/test.zig:4:38: 0x22272c in ??? (test)
const number = getNumberOrFail() catch unreachable;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
One way to avoid this crash is to test for an error instead of assuming a successful result, with
the if
expression:
test.zig
const warn = @import("std").debug.warn;
pub fn main() void {
const result = getNumberOrFail();
if (result) |number| {
warn("got number: {}\n", number);
} else |err| {
warn("got error: {}\n", @errorName(err));
}
}
fn getNumberOrFail() !i32 {
return error.UnableToReturnNumber;
}
$ zig build-exe test.zig
$ ./test
got error: UnableToReturnNumber
See also:
At compile-time:
test.zig
comptime {
const err = error.AnError;
const number = @errorToInt(err) + 10;
const invalid_err = @intToError(number);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:4:25: error: integer value 11 represents no error
const invalid_err = @intToError(number);
^
At runtime:
test.zig
const std = @import("std");
pub fn main() void {
var err = error.AnError;
var number = @errorToInt(err) + 500;
var invalid_err = @intToError(number);
std.debug.warn("value: {}\n", number);
}
$ zig build-exe test.zig
$ ./test
invalid error code
/home/andy/dev/zig/docgen_tmp/test.zig:6:23: 0x22271a in ??? (test)
var invalid_err = @intToError(number);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
const Foo = enum {
A,
B,
C,
};
comptime {
const a: u2 = 3;
const b = @intToEnum(Foo, a);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:8:15: error: enum 'Foo' has no tag matching integer value 3
const b = @intToEnum(Foo, a);
^
/home/andy/dev/zig/docgen_tmp/test.zig:1:13: note: 'Foo' declared here
const Foo = enum {
^
At runtime:
test.zig
const std = @import("std");
const Foo = enum {
A,
B,
C,
};
pub fn main() void {
var a: u2 = 3;
var b = @intToEnum(Foo, a);
std.debug.warn("value: {}\n", @tagName(b));
}
$ zig build-exe test.zig
$ ./test
invalid enum value
/home/andy/dev/zig/docgen_tmp/test.zig:11:13: 0x2226fd in ??? (test)
var b = @intToEnum(Foo, a);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
const Set1 = error{
A,
B,
};
const Set2 = error{
A,
C,
};
comptime {
_ = @errSetCast(Set2, Set1.B);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:10:9: error: error.B not a member of error set 'Set2'
_ = @errSetCast(Set2, Set1.B);
^
At runtime:
test.zig
const std = @import("std");
const Set1 = error{
A,
B,
};
const Set2 = error{
A,
C,
};
pub fn main() void {
foo(Set1.B);
}
fn foo(set1: Set1) void {
const x = @errSetCast(Set2, set1);
std.debug.warn("value: {}\n", x);
}
$ zig build-exe test.zig
$ ./test
invalid error code
/home/andy/dev/zig/docgen_tmp/test.zig:15:15: 0x222724 in ??? (test)
const x = @errSetCast(Set2, set1);
^
/home/andy/dev/zig/docgen_tmp/test.zig:12:8: 0x2226ce in ??? (test)
foo(Set1.B);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x2226a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
const ptr = @intToPtr(*i32, 0x1);
const aligned = @alignCast(4, ptr);
}
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes
const aligned = @alignCast(4, ptr);
^
At runtime:
test.zig
pub fn main() !void {
var array align(4) = []u32{ 0x11111111, 0x11111111 };
const bytes = @sliceToBytes(array[0..]);
if (foo(bytes) != 0x11111111) return error.Wrong;
}
fn foo(bytes: []u8) u32 {
const slice4 = bytes[1..5];
const int_slice = @bytesToSlice(u32, @alignCast(4, slice4));
return int_slice[0];
}
$ zig build-exe test.zig
$ ./test
incorrect alignment
/home/andy/dev/zig/docgen_tmp/test.zig:8:56: 0x2229ff in ??? (test)
const int_slice = @bytesToSlice(u32, @alignCast(4, slice4));
^
/home/andy/dev/zig/docgen_tmp/test.zig:4:12: 0x22283e in ??? (test)
if (foo(bytes) != 0x11111111) return error.Wrong;
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:96:22: 0x2226db in ??? (test)
root.main() catch |err| {
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x222655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x2224b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x222370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
At compile-time:
test.zig
comptime {
var f = Foo{ .int = 42 };
f.float = 12.34;
}
const Foo = union {
float: f32,
int: u32,
};
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:3:6: error: accessing union field 'float' while field 'int' is set
f.float = 12.34;
^
At runtime:
test.zig
const std = @import("std");
const Foo = union {
float: f32,
int: u32,
};
pub fn main() void {
var f = Foo{ .int = 42 };
bar(&f);
}
fn bar(f: *Foo) void {
f.float = 12.34;
std.debug.warn("value: {}\n", f.float);
}
$ zig build-exe test.zig
$ ./test
access of inactive union field
/home/andy/dev/zig/docgen_tmp/test.zig:14:6: 0x22a738 in ??? (test)
f.float = 12.34;
^
/home/andy/dev/zig/docgen_tmp/test.zig:10:8: 0x22a6dc in ??? (test)
bar(&f);
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:86:22: 0x22a6a9 in ??? (test)
root.main();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:70:20: 0x22a655 in ??? (test)
return callMain();
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:64:39: 0x22a4b8 in ??? (test)
std.os.posix.exit(callMainWithArgs(argc, argv, envp));
^
/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:5: 0x22a370 in ??? (test)
@noInlineCall(posixCallMainAndExit);
^
This safety is not available for extern
or packed
unions.
To change the active field of a union, assign the entire union, like this:
test.zig
const std = @import("std");
const Foo = union {
float: f32,
int: u32,
};
pub fn main() void {
var f = Foo{ .int = 42 };
bar(&f);
}
fn bar(f: *Foo) void {
f.* = Foo{ .float = 12.34 };
std.debug.warn("value: {}\n", f.float);
}
$ zig build-exe test.zig
$ ./test
value: 1.23400001e+01
To change the active field of a union when a meaningful value for the field is not known, use undefined, like this:
test.zig
const std = @import("std");
const Foo = union {
float: f32,
int: u32,
};
pub fn main() void {
var f = Foo{ .int = 42 };
f = Foo{ .float = undefined };
bar(&f);
std.debug.warn("value: {}\n", f.float);
}
fn bar(f: *Foo) void {
f.float = 12.34;
}
$ zig build-exe test.zig
$ ./test
value: 1.23400001e+01
TODO
TODO: explain no default allocator in zig
TODO: show how to use the allocator interface
TODO: mention debug allocator
TODO: importance of checking for allocation failure
TODO: mention overcommit and the OOM Killer
TODO: mention recursion
See also:
Compile variables are accessible by importing the "builtin"
package,
which the compiler makes available to every Zig source file. It contains
compile-time constants such as the current target, endianness, and release mode.
const builtin = @import("builtin");
const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
Example of what is imported with @import("builtin")
:
pub const StackTrace = struct {
index: usize,
instruction_addresses: []usize,
};
pub const Os = enum {
freestanding,
ananas,
cloudabi,
dragonfly,
freebsd,
fuchsia,
ios,
kfreebsd,
linux,
lv2,
macosx,
netbsd,
openbsd,
solaris,
windows,
haiku,
minix,
rtems,
nacl,
cnk,
aix,
cuda,
nvcl,
amdhsa,
ps4,
elfiamcu,
tvos,
watchos,
mesa3d,
contiki,
amdpal,
zen,
};
pub const Arch = enum {
armv8_3a,
armv8_2a,
armv8_1a,
armv8,
armv8r,
armv8m_baseline,
armv8m_mainline,
armv7,
armv7em,
armv7m,
armv7s,
armv7k,
armv7ve,
armv6,
armv6m,
armv6k,
armv6t2,
armv5,
armv5te,
armv4t,
armebv8_3a,
armebv8_2a,
armebv8_1a,
armebv8,
armebv8r,
armebv8m_baseline,
armebv8m_mainline,
armebv7,
armebv7em,
armebv7m,
armebv7s,
armebv7k,
armebv7ve,
armebv6,
armebv6m,
armebv6k,
armebv6t2,
armebv5,
armebv5te,
armebv4t,
aarch64,
aarch64_be,
arc,
avr,
bpfel,
bpfeb,
hexagon,
mips,
mipsel,
mips64,
mips64el,
msp430,
nios2,
powerpc,
powerpc64,
powerpc64le,
r600,
amdgcn,
riscv32,
riscv64,
sparc,
sparcv9,
sparcel,
s390x,
tce,
tcele,
thumb,
thumbeb,
i386,
x86_64,
xcore,
nvptx,
nvptx64,
le32,
le64,
amdil,
amdil64,
hsail,
hsail64,
spir,
spir64,
kalimbav3,
kalimbav4,
kalimbav5,
shave,
lanai,
wasm32,
wasm64,
renderscript32,
renderscript64,
};
pub const Environ = enum {
unknown,
gnu,
gnuabin32,
gnuabi64,
gnueabi,
gnueabihf,
gnux32,
code16,
eabi,
eabihf,
android,
musl,
musleabi,
musleabihf,
msvc,
itanium,
cygnus,
coreclr,
simulator,
};
pub const ObjectFormat = enum {
unknown,
coff,
elf,
macho,
wasm,
};
pub const GlobalLinkage = enum {
Internal,
Strong,
Weak,
LinkOnce,
};
pub const AtomicOrder = enum {
Unordered,
Monotonic,
Acquire,
Release,
AcqRel,
SeqCst,
};
pub const AtomicRmwOp = enum {
Xchg,
Add,
Sub,
And,
Nand,
Or,
Xor,
Max,
Min,
};
pub const Mode = enum {
Debug,
ReleaseSafe,
ReleaseFast,
ReleaseSmall,
};
pub const TypeId = enum {
Type,
Void,
Bool,
NoReturn,
Int,
Float,
Pointer,
Array,
Struct,
ComptimeFloat,
ComptimeInt,
Undefined,
Null,
Optional,
ErrorUnion,
ErrorSet,
Enum,
Union,
Fn,
Namespace,
BoundFn,
ArgTuple,
Opaque,
Promise,
};
pub const TypeInfo = union(TypeId) {
Type: void,
Void: void,
Bool: void,
NoReturn: void,
Int: Int,
Float: Float,
Pointer: Pointer,
Array: Array,
Struct: Struct,
ComptimeFloat: void,
ComptimeInt: void,
Undefined: void,
Null: void,
Optional: Optional,
ErrorUnion: ErrorUnion,
ErrorSet: ErrorSet,
Enum: Enum,
Union: Union,
Fn: Fn,
Namespace: void,
BoundFn: Fn,
ArgTuple: void,
Opaque: void,
Promise: Promise,
pub const Int = struct {
is_signed: bool,
bits: u8,
};
pub const Float = struct {
bits: u8,
};
pub const Pointer = struct {
size: Size,
is_const: bool,
is_volatile: bool,
alignment: u32,
child: type,
pub const Size = enum {
One,
Many,
Slice,
};
};
pub const Array = struct {
len: usize,
child: type,
};
pub const ContainerLayout = enum {
Auto,
Extern,
Packed,
};
pub const StructField = struct {
name: []const u8,
offset: ?usize,
field_type: type,
};
pub const Struct = struct {
layout: ContainerLayout,
fields: []StructField,
defs: []Definition,
};
pub const Optional = struct {
child: type,
};
pub const ErrorUnion = struct {
error_set: type,
payload: type,
};
pub const Error = struct {
name: []const u8,
value: usize,
};
pub const ErrorSet = struct {
errors: []Error,
};
pub const EnumField = struct {
name: []const u8,
value: usize,
};
pub const Enum = struct {
layout: ContainerLayout,
tag_type: type,
fields: []EnumField,
defs: []Definition,
};
pub const UnionField = struct {
name: []const u8,
enum_field: ?EnumField,
field_type: type,
};
pub const Union = struct {
layout: ContainerLayout,
tag_type: ?type,
fields: []UnionField,
defs: []Definition,
};
pub const CallingConvention = enum {
Unspecified,
C,
Cold,
Naked,
Stdcall,
Async,
};
pub const FnArg = struct {
is_generic: bool,
is_noalias: bool,
arg_type: ?type,
};
pub const Fn = struct {
calling_convention: CallingConvention,
is_generic: bool,
is_var_args: bool,
return_type: ?type,
async_allocator_type: ?type,
args: []FnArg,
};
pub const Promise = struct {
child: ?type,
};
pub const Definition = struct {
name: []const u8,
is_pub: bool,
data: Data,
pub const Data = union(enum) {
Type: type,
Var: type,
Fn: FnDef,
pub const FnDef = struct {
fn_type: type,
inline_type: Inline,
calling_convention: CallingConvention,
is_var_args: bool,
is_extern: bool,
is_export: bool,
lib_name: ?[]const u8,
return_type: type,
arg_names: [][] const u8,
pub const Inline = enum {
Auto,
Always,
Never,
};
};
};
};
};
pub const FloatMode = enum {
Strict,
Optimized,
};
pub const Endian = enum {
Big,
Little,
};
pub const endian = Endian.Little;
pub const is_test = false;
pub const os = Os.linux;
pub const arch = Arch.x86_64;
pub const environ = Environ.gnu;
pub const object_format = ObjectFormat.elf;
pub const mode = Mode.Debug;
pub const link_libc = false;
pub const have_error_return_tracing = false;
pub const __zig_test_fn_slice = {}; // overwritten later
See also:
TODO: explain how root source file finds other files
TODO: pub fn main
TODO: pub fn panic
TODO: if linking with libc you can use export fn main
TODO: order independent top level declarations
TODO: lazy analysis
TODO: using comptime { _ = @import() }
TODO: basic usage
TODO: lazy analysis
TODO: --test-filter
TODO: --test-name-prefix
TODO: testing in releasefast and releasesafe mode. assert still works
TODO: explain purpose, it's supposed to replace make/cmake
TODO: example of building a zig executable
TODO: example of building a C library
Although Zig is independent of C, and, unlike most other languages, does not depend on libc, Zig acknowledges the importance of interacting with existing C code.
There are a few ways that Zig facilitates C interop.
These have guaranteed C ABI compatibility and can be used like any other type.
c_short
c_ushort
c_int
c_uint
c_long
c_ulong
c_longlong
c_ulonglong
c_longdouble
c_void
See also:
test.zig
extern fn puts([*]const u8) void;
pub fn main() void {
puts(c"this has a null terminator");
puts(
c\\and so
c\\does this
c\\multiline C string literal
);
}
$ zig build-exe test.zig --library c
$ ./test
this has a null terminator
and so
does this
multiline C string literal
See also:
The @cImport
builtin function can be used
to directly import symbols from .h files:
test.zig
const c = @cImport({
// See https://github.com/ziglang/zig/issues/515
@cDefine("_NO_CRT_STDIO_INLINE", "1");
@cInclude("stdio.h");
});
pub fn main() void {
_ = c.printf(c"hello\n");
}
$ zig build-exe test.zig --library c
$ ./test
hello
The @cImport
function takes an expression as a parameter.
This expression is evaluated at compile-time and is used to control
preprocessor directives and include multiple .h files:
const builtin = @import("builtin");
const c = @cImport({
@cDefine("NDEBUG", builtin.mode == builtin.Mode.ReleaseFast);
if (something) {
@cDefine("_GNU_SOURCE", {});
}
@cInclude("stdlib.h");
if (something) {
@cUndef("_GNU_SOURCE");
}
@cInclude("soundio.h");
});
See also:
One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages
to call into. The export
keyword in front of functions, variables, and types causes them to
be part of the library API:
mathtest.zig
export fn add(a: i32, b: i32) i32 {
return a + b;
}
To make a shared library:
$ zig build-lib mathtest.zig
To make a static library:
$ zig build-lib mathtest.zig --static
Here is an example with the Zig Build System:
test.c
// This header is generated by zig from mathtest.zig
#include "mathtest.h"
#include <assert.h>
int main(int argc, char **argv) {
assert(add(42, 1337) == 1379);
return 0;
}
build.zig
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addCExecutable("test");
exe.addCompileFlags([][]const u8{"-std=c99"});
exe.addSourceFile("test.c");
exe.linkLibrary(lib);
b.default_step.dependOn(&exe.step);
const run_cmd = b.addCommand(".", b.env_map, [][]const u8{exe.getOutputPath()});
run_cmd.step.dependOn(&exe.step);
const test_step = b.step("test", "Test the program");
test_step.dependOn(&run_cmd.step);
}
terminal
$ zig build
$ ./test
$ echo $?
0
You can mix Zig object files with any other object files that respect the C ABI. Example:
base64.zig
const base64 = @import("std").base64;
export fn decode_base_64(
dest_ptr: [*]u8,
dest_len: usize,
source_ptr: [*]const u8,
source_len: usize,
) usize {
const src = source_ptr[0..source_len];
const dest = dest_ptr[0..dest_len];
const base64_decoder = base64.standard_decoder_unsafe;
const decoded_size = base64_decoder.calcSize(src);
base64_decoder.decode(dest[0..decoded_size], src);
return decoded_size;
}
test.c
// This header is generated by zig from base64.zig
#include "base64.h"
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv) {
const char *encoded = "YWxsIHlvdXIgYmFzZSBhcmUgYmVsb25nIHRvIHVz";
char buf[200];
size_t len = decode_base_64(buf, 200, encoded, strlen(encoded));
buf[len] = 0;
puts(buf);
return 0;
}
build.zig
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addCExecutable("test");
exe.addCompileFlags([][]const u8 {
"-std=c99",
});
exe.addSourceFile("test.c");
exe.addObject(obj);
exe.setOutputPath(".");
b.default_step.dependOn(&exe.step);
}
terminal
$ zig build
$ ./test
all your base are belong to us
See also:
Zig supports generating code for all targets that LLVM supports. Here is
what it looks like to execute zig targets
on a Linux x86_64
computer:
$ zig targets
Architectures:
armv8_2a
armv8_1a
armv8
armv8r
armv8m_baseline
armv8m_mainline
armv7
armv7em
armv7m
armv7s
armv7k
armv7ve
armv6
armv6m
armv6k
armv6t2
armv5
armv5te
armv4t
armeb
aarch64
aarch64_be
avr
bpfel
bpfeb
hexagon
mips
mipsel
mips64
mips64el
msp430
nios2
powerpc
powerpc64
powerpc64le
r600
amdgcn
riscv32
riscv64
sparc
sparcv9
sparcel
s390x
tce
tcele
thumb
thumbeb
i386
x86_64 (native)
xcore
nvptx
nvptx64
le32
le64
amdil
amdil64
hsail
hsail64
spir
spir64
kalimbav3
kalimbav4
kalimbav5
shave
lanai
wasm32
wasm64
renderscript32
renderscript64
Operating Systems:
freestanding
ananas
cloudabi
dragonfly
freebsd
fuchsia
ios
kfreebsd
linux (native)
lv2
macosx
netbsd
openbsd
solaris
windows
haiku
minix
rtems
nacl
cnk
bitrig
aix
cuda
nvcl
amdhsa
ps4
elfiamcu
tvos
watchos
mesa3d
contiki
zen
Environments:
unknown
gnu (native)
gnuabi64
gnueabi
gnueabihf
gnux32
code16
eabi
eabihf
android
musl
musleabi
musleabihf
msvc
itanium
cygnus
amdopencl
coreclr
opencl
The Zig Standard Library (@import("std")
) has architecture, environment, and operating sytsem
abstractions, and thus takes additional work to support more platforms.
Not all standard library code requires operating system abstractions, however,
so things such as generic data structures work an all above platforms.
The current list of targets supported by the Zig Standard Library is:
These coding conventions are not enforced by the compiler, but they are shipped in this documentation along with the compiler in order to provide a point of reference, should anyone wish to point to an authority on agreed upon Zig coding style.
Roughly speaking: camelCaseFunctionName
, TitleCaseTypeName
,
snake_case_variable_name
. More precisely:
x
is a struct
(or an alias of a struct
),
then x
should be TitleCase
.
x
otherwise identifies a type, x
should have snake_case
.
x
is callable, and x
's return type is type
, then x
should be TitleCase
.
x
is otherwise callable, then x
should be camelCase
.
x
should be snake_case
.
Acronyms, initialisms, proper nouns, or any other word that has capitalization rules in written English are subject to naming conventions just like any other word. Even acronyms that are only 2 letters long are subject to these conventions.
These are general rules of thumb; if it makes sense to do something different,
do what makes sense. For example, if there is an established convention such as
ENOENT
, follow the established convention.
const namespace_name = @import("dir_name/file_name.zig");
var global_var: i32 = undefined;
const const_name = 42;
const primitive_type_alias = f32;
const string_alias = []u8;
const StructName = struct {};
const StructAlias = StructName;
fn functionName(param_name: TypeName) void {
var functionPointer = functionName;
functionPointer();
functionPointer = otherFunction;
functionPointer();
}
const functionAlias = functionName;
fn ListTemplateFunction(comptime ChildType: type, comptime fixed_size: usize) type {
return List(ChildType, fixed_size);
}
fn ShortList(comptime T: type, comptime n: usize) type {
return struct {
field_name: [n]T,
fn methodName() void {}
};
}
// The word XML loses its casing when used in Zig identifiers.
const xml_document =
\\<?xml version="1.0" encoding="UTF-8"?>
\\<document>
\\</document>
;
const XmlParser = struct {};
// The initials BE (Big Endian) are just another word in Zig identifier names.
fn readU32Be() u32 {}
See the Zig Standard Library for more examples.
Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.
Throughout all zig source code (including in comments), some codepoints are never allowed:
The codepoint U+000a (LF) (which is encoded as the single-byte value 0x0a) is the line terminator character. This character always terminates a line of zig source code (except possbly the last line of the file).
For some discussion on the rationale behind these design decisions, see issue #663
Root = many(TopLevelItem) EOF
TopLevelItem = CompTimeExpression(Block) | TopLevelDecl | TestDecl
TestDecl = "test" String Block
TopLevelDecl = option("pub") (FnDef | ExternDecl | GlobalVarDecl | UseDecl)
GlobalVarDecl = option("export") VariableDeclaration ";"
LocalVarDecl = option("comptime") VariableDeclaration
VariableDeclaration = ("var" | "const") Symbol option(":" TypeExpr) option("align" "(" Expression ")") option("section" "(" Expression ")") "=" Expression
ContainerMember = (ContainerField | FnDef | GlobalVarDecl)
ContainerField = Symbol option(":" PrefixOpExpression) option("=" PrefixOpExpression) ","
UseDecl = "use" Expression ";"
ExternDecl = "extern" option(String) (FnProto | VariableDeclaration) ";"
FnProto = option("nakedcc" | "stdcallcc" | "extern" | ("async" option("<" Expression ">"))) "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("!") (TypeExpr | "var")
FnDef = option("inline" | "export") FnProto Block
ParamDeclList = "(" list(ParamDecl, ",") ")"
ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "var" | "...")
Block = option(Symbol ":") "{" many(Statement) "}"
Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
TypeExpr = (PrefixOpExpression "!" PrefixOpExpression) | PrefixOpExpression
BlockOrExpression = Block | Expression
Expression = TryExpression | ReturnExpression | BreakExpression | AssignmentExpression | CancelExpression | ResumeExpression
AsmExpression = "asm" option("volatile") "(" String option(AsmOutput) ")"
AsmOutput = ":" list(AsmOutputItem, ",") option(AsmInput)
AsmInput = ":" list(AsmInputItem, ",") option(AsmClobbers)
AsmOutputItem = "[" Symbol "]" String "(" (Symbol | "->" TypeExpr) ")"
AsmInputItem = "[" Symbol "]" String "(" Expression ")"
AsmClobbers= ":" list(String, ",")
UnwrapExpression = BoolOrExpression (UnwrapOptional | UnwrapError) | BoolOrExpression
UnwrapOptional = "orelse" Expression
UnwrapError = "catch" option("|" Symbol "|") Expression
AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "*%=" | "+%=" | "-%="
BlockExpression(body) = Block | IfExpression(body) | IfErrorExpression(body) | TestExpression(body) | WhileExpression(body) | ForExpression(body) | SwitchExpression | CompTimeExpression(body) | SuspendExpression(body)
CompTimeExpression(body) = "comptime" body
SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}"
SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbol "|") Expression ","
SwitchItem = Expression | (Expression "..." Expression)
ForExpression(body) = option(Symbol ":") option("inline") "for" "(" Expression ")" option("|" option("*") Symbol option("," Symbol) "|") body option("else" BlockExpression(body))
BoolOrExpression = BoolAndExpression "or" BoolOrExpression | BoolAndExpression
ReturnExpression = "return" option(Expression)
TryExpression = "try" Expression
AwaitExpression = "await" Expression
BreakExpression = "break" option(":" Symbol) option(Expression)
CancelExpression = "cancel" Expression;
ResumeExpression = "resume" Expression;
Defer(body) = ("defer" | "deferror") body
IfExpression(body) = "if" "(" Expression ")" body option("else" BlockExpression(body))
SuspendExpression(body) = "suspend" option( body )
IfErrorExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body "else" "|" Symbol "|" BlockExpression(body)
TestExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" BlockExpression(body))
WhileExpression(body) = option(Symbol ":") option("inline") "while" "(" Expression ")" option("|" option("*") Symbol "|") option(":" "(" Expression ")") body option("else" option("|" Symbol "|") BlockExpression(body))
BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression
ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
ComparisonOperator = "==" | "!=" | "<" | ">" | "<=" | ">="
BinaryOrExpression = BinaryXorExpression "|" BinaryOrExpression | BinaryXorExpression
BinaryXorExpression = BinaryAndExpression "^" BinaryXorExpression | BinaryAndExpression
BinaryAndExpression = BitShiftExpression "&" BinaryAndExpression | BitShiftExpression
BitShiftExpression = AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression
BitShiftOperator = "<<" | ">>"
AdditionExpression = MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression
AdditionOperator = "+" | "-" | "++" | "+%" | "-%"
MultiplyExpression = CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
CurlySuffixExpression = TypeExpr option(ContainerInitExpression)
MultiplyOperator = "||" | "*" | "/" | "%" | "**" | "*%"
PrefixOpExpression = PrefixOp TypeExpr | SuffixOpExpression
SuffixOpExpression = ("async" option("<" SuffixOpExpression ">") SuffixOpExpression FnCallExpression) | PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | ".*" | ".?")
FieldAccessExpression = "." Symbol
FnCallExpression = "(" list(Expression, ",") ")"
ArrayAccessExpression = "[" Expression "]"
SliceExpression = "[" Expression ".." option(Expression) "]"
ContainerInitExpression = "{" ContainerInitBody "}"
ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
StructLiteralField = "." Symbol "=" Expression
PrefixOp = "!" | "-" | "~" | (("*" | "[*]") option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "-%" | "try" | "await"
PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ContainerDecl | ("continue" option(":" Symbol)) | ErrorSetDecl | PromiseType
PromiseType = "promise" option("->" TypeExpr)
ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":" Integer ":" Integer) ")")) option("const") option("volatile") TypeExpr
GroupedExpression = "(" Expression ")"
KeywordLiteral = "true" | "false" | "null" | "undefined" | "error" | "unreachable" | "suspend"
ErrorSetDecl = "error" "{" list(Symbol, ",") "}"
ContainerDecl = option("extern" | "packed")
("struct" option(GroupedExpression) | "union" option("enum" option(GroupedExpression) | GroupedExpression) | ("enum" option(GroupedExpression)))
"{" many(ContainerMember) "}"


Articles
Create New Article
Publish
Save Draft
Delete Draft
Simple blog editor - A great way of learning
Enter text here


Galvanize Delivers
Home
Home
menu
Menu
Order
Royale with Cheese
$8.99
Add to Order
Arugula Pie
$11.99
Add to Order
Item
Item Price
Quanity
=
Price
Royale with Cheese
$8.99
4
35.96
Arugula Pie
$11.99
4
59.96
Smoked Swine
$14.99
4
47.96
Ice Cream Biscut
$7.99
4
31.96
0
=
Tax
=
T
Total
=
T
Smoked Swine
$14.99
Add to Order
Ice Cream Biscut
$7.99
Add to Order
account_circle
First Name
phone
Telephone
business
Address
Place an Order


Our Mission
Our mission is simple:To help build a better retail experience for all. WE think shopping should be fun, easy and bring the most value to our customers dollar. Buy different today!
SIGN UP!
DON'T FORGET TO SIGN-UP OR SIGN-IN!  ALSO, EVERY NEW ACCOUNT AUTOMATICALLY RECEIVES $5.00 DOLLARS IN J-CASH TO SPEND. BUY DIFFERENT TODAY !
Services
Gold Jewelry For You
"Bold and Classic!"
14K Gold Preloved Necklaces and Pendants from dainty to bold, classic to modern— shop our hand selected collection of beautiful preloved jewelry.
“Cool White Gold”
10K Necklaces, Pendants and Earrings in Cool White Gold! Compliment your yellow or rose colored jewelry with beautiful white gold!
“Your Style, Your Way”
14K Gold Earrings! From classic hoops to elegant spirals, our hand selected collection of gold earrings allows you to make your own style.
Our Mission
Our mission is simple:To help build a better retail experience for all. WE think shopping should be fun, easy and bring the most value to our customers dollar. Buy different today!
Why shop with us
Extroardinary Value We offer extroardinary value to every customer we serve. Feel free to compare us to any other online retailer. We want our customers to have the best retail experience,period!
Fast DeliveryWe dont want you to wait weeks for you new purchase. we will try our best to offer fast, free shipping to all of our valued customers.
100% Satisfaction We want you to be 100% sastisfied with your shopping experience. If you ever have a problem or question, we are here to help
Saul Goodman
Returning customer
I'm really out here BUYING DIFFERENT!
Sara Wilsson
one-time customer
I got some 14k preloved earring 6 months ago and they're still in great condition.
Jena Karlis
Felt the difference
I aint ever felt like I was buying different until is shopped at The J-Store Online.
Matt Brandon
Will never regret his decision
I bought different that day. I will never regret that. It's really different.
John Larson
Wife loved her gift
My wife loves how different I shopped for her. She could tell it was different.
Team
Check our Team


Toggle navigation
\(\mathbb{N}^3\)
Events
Members
Seminars
Contact
Sponsors
History
Files
Members of the network
University:
Chalmers
and
Göteborg University
Department:
Department of Mathematical Sciences
Faculty Members:
Michael Björklund (Professor)
Martin Raum (Professor)
Per Salberger (Professor)
Julia Brandes
Dennis Eriksson
Laura Fainsilber
Christian Johansson
Stefan Lemurell
Daniel Persson
Anders Södergren
Postdocs, PhD Students and Other Members:
Kirsti Biggs (Postdoc)
Lucile Devin (Postdoc)
Kristian Holm (Phd Student)
Tobias Magnusson (Phd Student)
Events of the Network organized:
\(\mathbb{N}^3\)-Days 3
\(\mathbb{N}^3\)-Days 5
Workshop in Number Theory and Dynamics, University of Göteborg and Chalmers University, 18-19 Aug 2016.
Where Geometry meets Number Theory - a conference in honour of the 60th birthday of Per Salberger, Chalmers University, 17-19 July 2017 (
LINK
)
N-cube Days VIII, Mittag-Leffler Institute, 24-29 Jun 2018.
\(\mathbb{N}^3\)-Days 11
, 15-16 Nov 2019.


This class will, given a DrugBank data file, parse its contents and output a tab-delimited
regular expression file suitable for import by the automaton generating software.
DrugBank() -
Constructor for class uk.ac.man.entitytagger.entities.misc.DrugBank


Contract registering an API of third party contract functions callable via Web3 Direct Democracy democratic process. API functions can be edited (add, remove) and executed by address contained in {Register_Authorities} list (Defined in the "Register" inherited contract)
Functions
Add the address of Agora Contract to {Register_Authorities}.
| Name | Type | Description |
|---|---|---|
| Name | string | Name of the {API_Register} contract |
| agora | address | Address of Agora contract |
Returns:
No parameters
Add an account address to {Register_Authorities}
| Name | Type | Description |
|---|---|---|
| authority | address | address to add to the {Register_Authorities} |
Returns:
No parameters
Add a third party smart contract to the API (it's address is added to {Contract} mapping and {List_Contracts} list)
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract to add to the API |
| name | bytes | Name of the smart contract. |
| description | bytes | Text describing the smart contract and justifying it's add to the API. Can be a hash |
Returns:
No parameters
Add a third party smart contract's function to the list of functions callable via the API.
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract. |
| function_selector | bytes4 | Function selector of the function |
Returns:
No parameters
**Add Documentation for the method here**
No parameters
Returns:
| Name | Type | Description |
|---|---|---|
| address |
**Add Documentation for the method here**
| Name | Type | Description |
|---|---|---|
| address |
Returns:
| Name | Type | Description |
|---|---|---|
| Name | bytes | |
| Description | bytes | |
| Timestamps | uint256 |
Make a call to a function of a third party smart contract belonging to the API
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract |
| data | bytes | Data corresponding to the function call. It's a bytes composed by the function selector + encoded parameters. It correspond to the field {data} of a transaction. |
Returns:
No parameters
Getter for {Register_Authorities}
No parameters
Returns:
| Name | Type | Description |
|---|---|---|
| bytes32[] |
Get the list of all function selector of a contract registered in the API.
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the contract |
Returns:
| Name | Type | Description |
|---|---|---|
| list_functions | bytes4[] |
Get the receipts of all call to a function of a contract registered in the API. It also returns the index of the function selector in the contract structure's {List_Functions} array.
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the contract |
| function_selector | bytes4 | Function selector of the function |
Returns:
| Name | Type | Description |
|---|---|---|
| index | uint256 | |
| receipts | tuple[] |
Get the list of all third party smart contract registered in the API.
No parameters
Returns:
| Name | Type | Description |
|---|---|---|
| list_contracts | bytes32[] |
The function Allows to change the Name of the Institution. The function is only callable by the {Constitution_Address}
No parameters
Returns:
| Name | Type | Description |
|---|---|---|
| string |
Removes an account address from the {Register_Authorities}
| Name | Type | Description |
|---|---|---|
| authority | address | address to remove from the {Register_Authorities} |
Returns:
No parameters
Remove a third party smart contract from the API
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract to remove from the API |
Returns:
No parameters
Remove a function from the list of third party smart contract's functions callable via the API
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract. |
| function_selector | bytes4 | Function selector of the function to remove. |
Returns:
No parameters
The function Allows to change the Constitution contract the current Institution obey to. The function is only callable by the {Constitution_Address}
| Name | Type | Description |
|---|---|---|
| new_constitution | address | Address of the new Constitution contract. |
Returns:
No parameters
The function Allows to change the Name of the Institution. The function is only callable by the {Constitution_Address}
| Name | Type | Description |
|---|---|---|
| name | string | New name of the Institution. |
Returns:
No parameters
Modify the name and description of third party contract registered in the API
| Name | Type | Description |
|---|---|---|
| contract_address | address | Address of the third party smart contract. |
| name | bytes | New name of the contract. |
| description | bytes | New description of the contract |
Returns:
No parameters
**Add Documentation for the method here**
No parameters
Returns:
| Name | Type | Description |
|---|---|---|
| uint8 |


As i cant solder to save my life, I see you can buy the Pi and the RFM12pi pre assembled but you cant the emontx from the shop?? Is it possible to buy it pre assembled with the firmware already flashed?
Plus can you connect more than one emontx to a base station? My solar PV is in a different place to my main meter.
Ian
Re: Pre Built EmonTX
You can have more than one emonTx sending to the same base.
On the soldering question, you could ask nicely in the "For Sale / Wanted / Services Offered" forum.
Re: Pre Built EmonTX
If you get stuck I will assemble it for you no problem (im in the uk in surrey).
Dave
Re: Pre Built EmonTX
Cheers Dave...
Is there a reason why they dont offer them pre assembled like the do with the rmf12pi?
I have arthritis in my hands so would be impossible for me to do it.
Ian
Re: Pre Built EmonTX
Hi Ian,
I imagine its because the rpi board is essentially an smd chip and some smallish discrete parts.
The emon-tx is thru hole, I know that the guys are working on a fully assembled smd based emon board but I don't think its for sale yet.
Happy to build a one off or two off if you need it, the software guys on here have helped me so why not!
Cheers
Dave
Re: Pre Built EmonTX
Another one that will help out where needs be, In the North of England (just in Yorkshire). so if local can save Royal Mails silly postage prices.
I've been helped out a few times and want to help where I can.


Read the text below. How much do you agree with the following statement: The black text adequately expresses the meaning of the gray text in English. Source sentence Target sentence


Formed in 2006, this American rock band climbed to success in 2008 with their breakout self-titled album. Their first breakout song, "Ain't No Rest for the Wicked" was featured in movies and video games such as the borderlands series. The band has since released five albums and is currently on tour with Beck. Their most recent album, "Social Cues," has been grammy nominated for Best Rock Album.
Matt Shultz: Lead Vocals, Rythm Guitar Brad Schult: Rythm Guitar, Keyboards Daniel Tichenor: Bass, Backing Vocals Jared Champion: Drums, Percussion
Back Against the Wall


--- layout: post title: Innovative Game Design Symposium date: 2005-01-26 00:00:00 categories: personal play ---
Anyone going to this? I'm kind of contemplating it - work committments permitting, though it looks quite interesting and dovetails nicely with a weekend.


| 8:30-10:05 | Period 1 | 95 minutes |
| 10:05-11:45 | Period 3 | 95 minutes |
| 11:45-12:25 | Lunch | 95 minutes |
| 12:30-2:05 | Period 5 | 95 minutes |
| 2:10-3:45 | Period 7 | 95 minutes |
| 8:30-10>05 | Period 1 | 95 minutes |
| 10:05-11:45 | Period 4 | 95 minutes |
| 11:45-12:25 | Lunch | 95 minutes |
| 12:30-2:05 | Period 6 | 95 minutes |
| 2:10-3:45 | Period 8 | 95 minutes |


Marginal improvement, but air quality in Delhi remains 'poor'
There was a respite on late Sunday evening as the AQI dropped to 198, which falls under "moderate" category. Gurgaon on Monday recorded an AQI of 138 (moderate), while Ghaziabad 231, Noida 212 and Greater Noida 204 . An AQI between 201 and 300 i...
by PTINew Delhi: The air quality in Delhi improved marginally on Monday but remained in the "poor" category for the second consecutive day. At 9 am on Monday, the air quality index (AQI) in the national capital stood at 207 against an AQI of 254 at the same time on Sunday.
However, there was a respite on late Sunday evening as the AQI dropped to 198, which falls under "moderate" category.
Gurgaon on Monday recorded an AQI of 138 (moderate), while Ghaziabad 231, Noida 212 and Greater Noida 204 .
An AQI between 201 and 300 is considered "poor", 301-400 "very poor" and 401-500 "severe".
Experts said strong winds due to western disturbance has helped dispersed pollutants in Delhi-NCR and other parts of north India.
On Sunday, the air quality index at 4 pm stood at 215, which falls in the "poor" category.


The application is not responding at the moment Starsky is temporarily unavailable. We apologize for the inconvenience.
Reload the application to try it again


@Alan Marry I belive that. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1 minuts ago@Stock Man Check this stock chart. This price is crazy!
2 hours ago@Kevin Smith Lorem ipsum unknown printer took a galley
2 minuts ago@Jonathan Febrick The standard chunk of Lorem Ipsum
1 hour ago@Alan Marry I belive that. Lorem Ipsum is simply dummy text of the printing and typesetting industry.
1 minuts ago@Kevin Smith Lorem ipsum unknown printer took a galley
2 minuts ago