source: src/examples/ArrayN.c @ cf0b892

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since cf0b892 was 4328016, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Starting ground work on N-dimension array proof of concept

  • Property mode set to 100644
File size: 487 bytes
RevLine 
[4328016]1#include <fstream>
2
3// [unsigned, unsigned] offset_to_index(unsigned offset, unsigned sx, unsigned sy)
4// {
5//     return [offset / sx, offset % sy];
6// }
7
8forall(otype index_t)
9index_t offset_to_index(unsigned offset, index_t size)
10{
11    return [offset / size.0, offset % size.1];
12}
13
14int main(int argc, char* argv[])
15{
16    unsigned x = 0, y = 0, i = 0;
17    unsigned sx = 4, sy = 4;
18
19    i = 6;
20    [x, y] = offset_to_index(6, [sx, sy]);
21
22    sout | x | ' ' | y | endl;
23
24    return 0;
25}
Note: See TracBrowser for help on using the repository browser.