mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
26 lines
672 B
C
26 lines
672 B
C
// Copyright (c) 2021 Christoffer Lerno. All rights reserved.
|
|
// Use of this source code is governed by the MIT license
|
|
// a copy of which can be found in the LICENSE_STDLIB file.
|
|
module std::array;
|
|
import std::mem;
|
|
|
|
/**
|
|
* @require elements > 0
|
|
**/
|
|
macro alloc($Type, usize elements)
|
|
{
|
|
assert($Type.max / elements < $Type.sizeof);
|
|
$Type* ptr = mem::alloc($Type.sizeof * elements, $alignof($Type));
|
|
return ptr[0..(elements - 1)];
|
|
}
|
|
|
|
/**
|
|
* @require elements > 0
|
|
**/
|
|
macro calloc($Type, usize elements)
|
|
{
|
|
assert($Type.max / elements < $Type.sizeof);
|
|
$Type* ptr = mem::calloc($sizeof($Type) * elements, $alignof($Type));
|
|
return ptr[0..(elements - 1)];
|
|
}
|