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?
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.
* p = (int*) malloc (size * sizeof (int));
Run
translated to nim:
p = cast[ptr cint](alloc(size * sizeof(cint)))
Run
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.
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]`.
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
> 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
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
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.)
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?
10 matches
Mail list logo