• WolfLink@lemmy.ml
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    8 months ago

    Tbh 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; }

    • clyne@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      8 months ago

      At that point I would just use std::span if you can, then you also get the standard container/iterator interfaces for free.

    • xep@fedia.io
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      8 months ago

      The 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.