Re: create array at runtime

2019-06-05 Thread dossgen
I have been facing these issues and was unable to find out the reason behind the error but tried to fix it through [https://errorcode0x.com/resolve-lenovo-error-code-1802/](https://errorcode0x.com/resolve-lenovo-error-code-1802/). Is there any alternative way to fix those issues?

Re: create array at runtime

2019-06-04 Thread bpr
You can use [this](https://github.com/bpr/vla) which looks a bit broken now but if you remove the deprecated pragma it runs fine. I'll fix that ASAP.

Re: create array at runtime

2019-06-04 Thread treeform
* p = (int*) malloc (size * sizeof (int)); Run translated to nim: p = cast[ptr cint](alloc(size * sizeof(cint))) Run

Re: create array at runtime

2019-06-04 Thread GULPF
It's better to cast to `ptr UncheckedArray[cint]` since it's more semantically correct. Otherwise you need to add indexing operations to `ptr cint` which is not a good idea.

Re: create array at runtime

2019-06-04 Thread GULPF
The equivalent in Nim would be `ptr UncheckedArray[T]`, which is a pointer to an array without any range checking. That said, unless you have a good reason for using it you're better of with `seq[T]`.

Re: create array at runtime

2019-06-04 Thread treeform
You should use a seq. You would not need size as its part of seq as .len. type Stack[T] = object top: int A: seq[T] Run If you NOT going interface with C there is no point in using C style arrays. BUT if you want to emulate C ... some thing you

Re: create array at runtime

2019-06-04 Thread cantanima
> Variable-length array is a new feature in C99, which is not used much **and > is not available in C++**. Come again? This compiles _and runs_ just fine in `clang++`. I mean, just fine for a C++ program. // usage: ... // example: ./a.out 5 8 4 3 1 6 // has output 8 4

Re: create array at runtime

2019-06-04 Thread Santanu
int* p = (int*) malloc (size * sizeof (int)); Is there a way to write this in Nim or do I have to ffi malloc (and will it work?). I don't want a variable length container but to set the size dynamically. type Stack = object A: array[5, int] This works but the array size is fixed. I

Re: create array at runtime

2019-06-04 Thread Stefan_Salewski
Variable-length array is a new feature in C99, which is not used much and is not available in C++. For variable size containers in C++ Vector data type is generally used, and in pure Nim we generally use seq data type. (For C interop you may consider UncheckedArray.)

create array at runtime

2019-06-04 Thread Santanu
type Stack[T] = object top: int size: int A: array[size, T] Run This does not work as size is unknown at creation. How to create a ptr to array like in C?