• uis@lemm.ee
    link
    fedilink
    arrow-up
    9
    arrow-down
    7
    ·
    edit-2
    4 months ago

    strncpy becomes stringnumbercopy. You can see why short version is used.

    • lemmytellyousomething@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      14
      ·
      edit-2
      4 months ago

      And with a bit of namespacing and/or object orientation and usage of dots, it becomes perfectly readable.

      There are also camel case and underscores in other languages…

      BTW: How on earth should a newcomer know that the letter “n” in that word stands for number without having to google it? The newcomer could even assume that it’s a letter of the word string… And even, if you know that it stands for number, it’s still hard for me to understand what it means in this context… I actually had to google it… But that’s probably some C++ convention I don’t know about, because I don’t program in C++…

      • zagaberoo@beehaw.org
        link
        fedilink
        arrow-up
        5
        ·
        4 months ago

        C is a little older than namespacing and object orientation. C++ wasn’t even a glimmer in Bjarne’s eye when these conventions were laid down.

        And yes, having to google it is part of the design. Originally C programmers would have had to read actual manuals about this stuff. Once you learn the names you don’t really forget so it works well enough even now for ubiquitous standard library functions.

        And yet, C was an ergonomic revelation to programmers of the time. Now it’s the arcane grandpa that most youngsters don’t put up with.

        • uis@lemm.ee
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          4 months ago

          If n is smaller than the string length (as in: distance to first null byte) then you’re bound to have garbage in your return destination

          Wha? N is just maximum length of string to copy. Data after dst+n is unchanged.

          In retrospect null-terminated strings were a mistake, but so were many other things, at some point you just have to accept that there’s hysterical raisins everywhere.

          All hail length-prefixed strings!

            • uis@lemm.ee
              link
              fedilink
              arrow-up
              1
              ·
              4 months ago

              Let us not talk about situations where CHAR_BIT != 8 that’s not POSIX anyway.

              Yeah, let’s not talk about 20-bit one’s complement ints.

    • xigoi@lemmy.sdf.org
      link
      fedilink
      English
      arrow-up
      2
      ·
      4 months ago

      Why not just add function overloading to the language and have a function named copy that takes a string and an optional character count?