Logo

Programming-Idioms

  • C
  • Perl
my $x = $items[$#items];

$#items represents the last index variable for items array
my $x = $items[-1];

$items[] looks up a single element from list @items.
Negative indices count from the end of the list.
int length = sizeof(items) / sizeof(items[0]);
int x = items[length - 1];

Only works if items has not decayed to a pointer.

length is defined as the size of the items array in bytes, divided by the size of its first element in bytes.
X := Items'Last

X must be declared earlier.

New implementation...