How not to check array size in C++pvs-studio.comexternal-link lysdexic ( @lysdexic@programming.dev ) M C++@programming.devEnglish • 3 months ago message-square8fedilinkarrow-up120
arrow-up120external-linkHow not to check array size in C++pvs-studio.com lysdexic ( @lysdexic@programming.dev ) M C++@programming.devEnglish • 3 months ago message-square8fedilink
minus-square WolfLink ( @WolfLink@lemmy.ml ) linkfedilink4•3 months agoTbh if you aren’t already using someone else’s array implementation that includes length information, just write your own simple wrapper e.g. struct MyArrayWrapper { int *data; int length; }
minus-square clyne ( @clyne@discuss.tchncs.de ) linkfedilink2•3 months agoAt that point I would just use std::span if you can, then you also get the standard container/iterator interfaces for free.
minus-square xep ( @xep@fedia.io ) linkfedilink1•edit-23 months agoThe article did mention that that’s what you’d probably have to do. I have only one pointer (for example, if you created an array using new) In most cases, it’s necessary to rewrite the program a bit and add an array size passing. Sadly, that’s how it works.
Tbh if you aren’t already using someone else’s array implementation that includes length information, just write your own simple wrapper e.g.
At that point I would just use std::span if you can, then you also get the standard container/iterator interfaces for free.
The article did mention that that’s what you’d probably have to do.