Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
piker
on Jan 7, 2017
|
parent
|
context
|
favorite
| on:
C99/C11 dynamic array that mimics C++'s std::vecto...
Is there a simple way to write the ARRAY_PUSH_BACK without a macro?
inlined
on Jan 7, 2017
|
next
[–]
If you have a pointer-only array you could just make it based on void*. Primitives and by-value arrays make it a lot harder.
AlexeyBrin
on Jan 7, 2017
|
prev
[–]
Probably, if you use
memcpy
and store the size of the data type as an extra parameter in the containing struct.
inlined
on Jan 7, 2017
|
parent
[–]
I was thinking about that but I don't know what to do with the type of the param you're accepting. Could you do a const void* ref? Might just be easier to make it variadic.
AlexeyBrin
on Jan 7, 2017
|
root
|
parent
[–]
See this comment
https://news.ycombinator.com/item?id=13346432
. At this point creating a function like:
array_push_back(int nr_arguments, ...);
that will replace the original macro ~~should be possible~~. Actually it won't work without using non-standard compiler extensions like
typeof
.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: