blob: c7d2b587c3783a79c14c6a20954fe0c9fabc36f4 [file] [log] [blame]
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// @assertion int operator [](int index)
///
/// The 16-bit two's complement integer at address + 2 * index.
///
/// A Dart integer is truncated to 16 bits (as if by .toSigned(16)) before being
/// stored, and the 16-bit value is sign-extended when it is loaded.
///
/// @description Check that operator [](int index) returns int at
/// address + 2 * index.
/// @author sgrekhov@unipro.ru
import "dart:ffi";
import "package:ffi/ffi.dart";
import '../../../Utils/expect.dart';
void main() {
Pointer<Int16> p1 = calloc<Int16>(2);
try {
Pointer<Int16> p2 = new Pointer.fromAddress(p1.address + sizeOf<Int16>());
p1.value = 1;
p2.value = 42;
Expect.equals(1, p1[0]);
Expect.equals(42, p1[1]);
} finally {
calloc.free(p1);
}
}