Beej's guide to C programming, chapter 7: Strings

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 15

  • @onaecO
    @onaecO  9 หลายเดือนก่อน +3

    at 00:07:42 let me be more precise
    The string is stored in ROM and then memcpy is gonna copy the string from ROM ONTO THE STACK (I hope this was clear, but very often I imply too much, and explicit is better than implicit, one of the python credo here haha)
    The memcpy thing is done for performance reasons.

    • @silloo2072
      @silloo2072 9 หลายเดือนก่อน

      So if we get the stack address of the string can we change the string?

    • @onaecO
      @onaecO  9 หลายเดือนก่อน +1

      yeah of course, char str[ ] is always modifiable, living on the stack. The thing I showed in the video, is just how the compiler achieves the initialization. Whit a mov (short str) or a memcpy ( for longer ones). Here assembly would be handy indeed

    • @silloo2072
      @silloo2072 9 หลายเดือนก่อน

      @@onaecO oh okay

  • @chacho1155
    @chacho1155 5 หลายเดือนก่อน

    Such a great fucking video. Thank you for making great content. I’ve been watching your printf video as well. It would be interesting to see a printf implementation without the stdarg library.

  • @silloo2072
    @silloo2072 9 หลายเดือนก่อน +1

    Please can you help me I am a beginner++ in c and I am making my first lexer, I have 3 major problem, when at the end of the file a put a space, it doesn't skip the space, when i creat a new line I doesn't skip, and when the file is 25 letter long or plus when I print all the token I get some random characters and the correct token at the same time, thanks for doing videos, I love them

    • @onaecO
      @onaecO  9 หลายเดือนก่อน +1

      Do u have a repo to share? It's hard to spot the bugs otherwise
      Btw The best book related to this I can recall is this ->craftinginterpreters.com/

    • @silloo2072
      @silloo2072 9 หลายเดือนก่อน

      @@onaecO 😢20 th comment

  • @JoaoJGabriel
    @JoaoJGabriel 9 หลายเดือนก่อน

    That's so cool! So does that also mean a pointer to a character is not the same as an array of characters, aka a string? It's so confusing when you extrapolate from "they can, most of the time, be used interchangeably" to "they are the same thing". Taking a step back, it almost sounds stupid, right? A char *s initializes a pointer and a char s[ ] initializes a random access, contiguous block of memory (i.e. an array)... duh!

    • @onaecO
      @onaecO  9 หลายเดือนก่อน +1

      To wrap it up logically:
      1) strings are char arrays type (const to be pedantic)
      2)Being arrays, as u know, they decay ( Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points to the initial element of the array object...stackoverflow.com/questions/57268963/what-is-array-decay-in-c-and-when-it-happen)
      3) Being a string literas used as an initializer (e.g. char s[] = "lol"), the literal "lol" does not decay to ptr from the standard, indeed u cannot assign a ptr to an array.
      For more->en.cppreference.com/w/c/language/array_initialization
      Many details this freaking C 🦖

  • @themadmen1717
    @themadmen1717 8 หลายเดือนก่อน

    Can I do 42 projects without being in 42 school just out of curiosity ? Like i found a bunch of small books about C and C++ related to 42 is that it ? Is there other sources ?

    • @onaecO
      @onaecO  8 หลายเดือนก่อน

      Yeah definetely, you can find everything about 42 in this repo ->>github.com/pasqualerossi

  • @silloo2072
    @silloo2072 8 หลายเดือนก่อน

    Why no new video

    • @onaecO
      @onaecO  8 หลายเดือนก่อน +2

      😂😂
      Cause I started working, not so much free time. But I will finish this series, promise!

    • @silloo2072
      @silloo2072 8 หลายเดือนก่อน

      @@onaecO oh good for you