C considered dangerous
C considered dangerous
Posted Sep 4, 2018 5:19 UTC (Tue) by ncm (guest, #165)In reply to: C considered dangerous by zlynx
Parent article: C considered dangerous
Complicating the interface for this and similar functions amounts to piling deck chairs on the Titanic into an obstacle course.
It is more than a little stupid to write a new program in C. All the typical pitfalls of pointer manipulations just don't arise in C++. C++ does still have integer overflow UB, as does Rust, and anyway unsigned integers wrapping around is nowhere near so benign as many like to believe.
There would be no problem with C++ in the Linux kernel if not for mindless bigotry, with many fewer opportunities for silly-bugger mistakes, and both faster and shorter code. It will happen eventually. It might happen first in FreeBSD, as the blinkered ancients there are closer to retirement.
Posted Sep 4, 2018 6:46 UTC (Tue)
by quotemstr (subscriber, #45331)
[Link] (5 responses)
That's absurd nonsense. You must be talking about different implementations of memcpy and memmove. so it's not an apples-to-apples comparison. You can always implement memcpy by taking memmove and baking in the memory-direction branches, which means that no matter how efficient your memmove, you can generate an even _more_ efficient memcpy out of it.
I can imagine memmove and memcpy being equally fast, but memmove being faster, by doing more work? Something is clearly wrong with the comparison.
Posted Sep 5, 2018 23:03 UTC (Wed)
by jreiser (subscriber, #11027)
[Link] (4 responses)
Posted Sep 5, 2018 23:45 UTC (Wed)
by quotemstr (subscriber, #45331)
[Link] (3 responses)
Posted Sep 6, 2018 3:42 UTC (Thu)
by jreiser (subscriber, #11027)
[Link] (2 responses)
Posted Sep 6, 2018 6:55 UTC (Thu)
by liw (subscriber, #6379)
[Link]
I tried writing a benchmark. GCC optimised it away.
Posted Sep 6, 2018 7:14 UTC (Thu)
by quotemstr (subscriber, #45331)
[Link]
Posted Sep 21, 2018 18:14 UTC (Fri)
by mathstuf (subscriber, #69389)
[Link]
No, Rust defines integer overflow as twos-complement (though in debug builds it will panic). You can use an always-panicking addition however, but that's not the default.
C considered dangerous
memmove faster than memcpy for small N
memmove faster than memcpy for small N
memmove faster than memcpy for small N
memmove faster than memcpy for small N
memmove faster than memcpy for small N
C considered dangerous
