Пропустить навигацию
You cannot add to a void pointer in C. The compiler does not know the size.
0:00 / 1:37

You cannot add to a void pointer in C. The compiler does not know the size.

tetsuo

@tetsuoai241 тыс. подписчиков

Открыть в X
612 отметок «Нравится»СкачатьОригинальный пост

28 004 просмотра

You cannot add to a void pointer in C. The compiler does not know the size. The everyday fix is to cast it to char* so the math is in bytes, then multiply by the element size yourself. Stanford CS107, lecture 4

15 комментариев

Комментарии из оригинального поста в X (Twitter)

  • Фото профиля acidburn

    @signerless

    this is what matters

    5 отметок «Нравится»

  • Фото профиля Jack

    @jackisgeeky

    You shouldn’t be using void pointers in the first place.

    3 отметки «Нравится»

  • Фото профиля Ray Epps

    @rayeppsonx

    there was a time when i was addicted to the stanford and harvard cs class recordings

    2 отметки «Нравится»

  • Фото профиля JETLAB-X

    @JETLABX

    Good Lord… flashback nightmares… I despised Object C/C++ glad XCode lets me do stuff with Swift.

    2 отметки «Нравится»

  • Фото профиля BullBear.News

    @bullbear_info

    Nothing like realizing at 2 AM that your pointer arithmetic on a void star just silently broke on ARM because the ABI handles things differently.

    2 отметки «Нравится»

  • Фото профиля Adrien Chauvet

    @adrien_chauvet

    Thank God, with AI it's becoming increasingly possible to create software without having to struggle with such hieroglyphs.

    1 отметка «Нравится»

  • Фото профиля symbols

    @japaneseremedy

    I am self taught and felt like an imposter for all the 15years until I watched this lecture, then I saw my true mind.

    1 отметка «Нравится»

  • Фото профиля Chris Ziomkowski

    @ZiomkowskiChris

    I worked on a custom architecture that didn't have byte addressing, so char* was the same as int*. Assuming char* is only 1 byte wide is a very bad idea. You should cast void* to uint64_t and do your work as integers if you want it to be portable.

    1 отметка «Нравится»

  • Фото профиля Deepak

    @HaXX0R

    hmm interesting.

  • Фото профиля Gustavo Rocambóli

    @Floripa2006

    2026 bro no one cares anymore

  • Фото профиля 音GATO

    @realRiverC

    void pointers, the real polymorphism

  • Фото профиля ᴅ ᴇ ᴀ ᴅ ʙ ᴏ ʏ

    @DeadboyEzra

    Boy, you don’t want my ass multiplying.

  • Фото профиля Mēgan DeMarco

    @Musk_Megan2026

    No comprehend lol I actually don't know what you mean by this one explain please

  • Фото профиля Pitchfork & Torch ♞

    @SuddenlyJon

    void* can’t count. We measure in chars!

  • Фото профиля Clank

    @clankenluben

    Wow even more basic shit information will it ever stop thank you