Ariana
ok that is painful
Hackers
Wow!
Hackers
BinaryByter
USE REALLOC
BinaryByter
(unless you haven't implemented realloc yet)
Mihail
op said he's using c
BinaryByter
so?
BinaryByter
what does OP mean?
Mihail
what does OP mean?
original poster
BinaryByter
oh
Mihail
and he suggested using std::vector
BinaryByter
oh
BinaryByter
in general
BinaryByter
just don't use C
Mihail
true
Mihail
but if he's already got a C codebase a conversion won't be easy and for such a small thing
BinaryByter
why would anybody have a C codebase?
Anonymous
systems without heaps
Ludovic 'Archivist'
systems without heaps
You can use freestanding c++ here too
Ludovic 'Archivist'
why would anybody have a C codebase?
The real reason is: because someone didn't knew C++ and wanted shit done to move on
Ludovic 'Archivist'
C is great
Maybe for very small projects in code size
Victor
very small, less then 1 KB→_→
Victor
I think assembly can be used =_=
Ludovic 'Archivist'
very small, less then 1 KB→_→
Very small for me is <2k LoC
Victor
the compiled binary is less than 1KB 😏
Ludovic 'Archivist'
the compiled binary is less than 1KB 😏
A real C dev makes it bigger using the power of macros and shitty code practices
Victor
wait, that is not an actual compilation, but assembling 😏
Victor
A real C dev makes it bigger using the power of macros and shitty code practices
The real reason is that the linker adds __libc_start_main function on Linux or the mainCRTStartup function on Windows
Anonymous
A real C dev makes it bigger using the power of macros and shitty code practices
Macros are good in that the improvement you make to the macro inproves it everywhere it is used
Anonymous
Maybe for very small projects in code size
Maybe for just about anything that needs to be fast or use a wide range of system level API
Ludovic 'Archivist'
And 99.95% of the time, C++ is not slower than C
Ludovic 'Archivist'
The 0.05% that subside are generally what is made my idiots that do not know the language
Anonymous
C seems more minimalistic and it seems to work very well for what I do
Ludovic 'Archivist'
C seems more minimalistic and it seems to work very well for what I do
Would you trust a medical injection pump to run in pure C tho
Anonymous
Would you trust a medical injection pump to run in pure C tho
I have heard Ada is used in critical applications
Ludovic 'Archivist'
Depends on the OS
Sometimes, none, the rest of the time, that is 99%, Linux with no hardening and an insecure telnet server but that is another thing
Ludovic 'Archivist'
Ludovic 'Archivist'
Nowadays, not so much
Ludovic 'Archivist'
Medical equipment may be the most terrifying thing I ever audited
Etaoin
in Haskell we can define x /= y = not (x == y) x == y = not (x /= y) in a typeclass
Etaoin
but how can I do this in C++?
Etaoin
I mean class A{ public: int f() { return 1; } int g() { return f(); } }; class B:public A{ public: int f() { return 2; } }; int main() { B x; cout<<x.f()<<x.g(); return 0; } gives 21
Etaoin
yes
Victor
That is very normal.
Victor
What do you expect?
Etaoin
I want to expose a interface to my user, that they can either implement function f or function g and with for some reason, g can be done by calling f and vice versa
Etaoin
for example f=(==) and g=(/=) in Haskell
Victor
And 99.95% of the time, C++ is not slower than C
Well, as for exactly the same code, C and C++'s performances are almost the same, but C++ loads more library, for example libstdc++.so.
Victor
I want to expose a interface to my user, that they can either implement function f or function g and with for some reason, g can be done by calling f and vice versa
I don't quite understand. Do you mean you want to call B::f() function in A::g() function? If so, you can write B::f() directly.
Etaoin
class A actually act as a interface and B is what the user (not I) writes that implement this interface
Etaoin
I expect both f and g in this interface, but either of them can be implemented with the other
Victor
class A actually act as a interface and B is what the user (not I) writes that implement this interface
Yes, A is in the third-party library, and B is written by user. Now what do you want?
Etaoin
and what's worse, it's in a performance bottleneck, so virtual function is not acceptable
Victor
I expect both f and g in this interface, but either of them can be implemented with the other
What does it mean by "either of them can be implemented with the other"? Do you mean either B::f() and B::g() can be implemented with the other
Victor
Or do you mean user can either implement B::g() and use A::f() or implement B::f() and use A::g()?
Etaoin
and what's worse it's in a performance bottleneck so virtual function is not acceptable
Etaoin
Etaoin
it's kinda like this
Etaoin
Etaoin
this, works, of course
Ludovic 'Archivist'
Etaoin
I know, but I tried several times and did not find a good solution
Ludovic 'Archivist'
You could make it a non interface class that stores function buffers (aka a size and a pointer) and relocates those in memory directly over pre-made placeholder, it will however not work correctly in multithreading
Etaoin
I think it could be done with templates
Ludovic 'Archivist'
I think it could be done with templates
It can if you can point those at compile time
Ludovic 'Archivist'
But then if you can they will likely be optimized in the case of virtual functions in most cases
Ludovic 'Archivist'
Also, unless your CPU dates from before 2009, you likely have a very suitable vtable prediction algo that reduce the eventual overhead of it if it is not optimized away down to a single cycle
Ludovic 'Archivist'
Which, compared to a loop, is pretty much nothing unless you loop on a very tiny datastructures
Ludovic 'Archivist'
Also, virtual inheritance works with references, get rid of that IStatistics*