lysdexic@programming.devM to C++@programming.devEnglish · 2 years agoHow not to check array size in C++pvs-studio.comexternal-linkmessage-square8linkfedilinkarrow-up129arrow-down12
arrow-up127arrow-down1external-linkHow not to check array size in C++pvs-studio.comlysdexic@programming.devM to C++@programming.devEnglish · 2 years agomessage-square8linkfedilink
minus-squareWolfLink@lemmy.mllinkfedilinkarrow-up5arrow-down1·2 years 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-squareclyne@discuss.tchncs.delinkfedilinkarrow-up2·2 years agoAt that point I would just use std::span if you can, then you also get the standard container/iterator interfaces for free.
minus-squarexep@fedia.iolinkfedilinkarrow-up1·2 years 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.