-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create dynamic arrays (i.e. size not known at compile time) #14
Comments
Mind that when using a C++ compiler, calls to smalloc() become invalid since it uses compound literals under the cover, which is valid C99 but invalid C++ (I think gcc/clang allows it as an extension but the value has static storage rather than automatic storage, so you can't put non-constant expressions in its initializer). You'd have to explicitely Using the API really wasn't designed for use in C++; if you can, try wrapping calls to smalloc in regular C functions compiled with a GNU99+ compiler. Another possibility if you're using C++11 and later would be to re-define the smalloc macro to use a lambda to set & call like described above: #undef smalloc
#define smalloc(...) ([&]() { s_smalloc_struct p { 0, __VA_ARGS__ }; return smalloc(&p); })() |
I don't quite follow what you are saying; it doesn't follow from what I wrote.
it fails with
Do you get a similar error result with your C compiler, or does it work? |
Oh, sorry, for some reason I thought this was related to your other issue. Looking again at how I implemented the sugar for smart_arr, this seems to be a limitation -- the macro initializes a structure with an element of type So, for this specific case you need to call |
I can write code like
smart char* pStrA = (char*)smart_arr(UNIQUE, char, 64);
but not
smart char* pStrA = (char*)smart_arr(UNIQUE, char, myArraySize);
Can you give me any ideas what I need to do? Either with using csptr, or changing it.
Thanks
The text was updated successfully, but these errors were encountered: