Skip navigation
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

@tetsuoai241K followers

Visit on X
612 likesDownloadOriginal post

28,004 views

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 Comments

Comments from the original post on X (Twitter)

  • acidburn's profile picture

    @signerless

    this is what matters

    5 likes

  • Jack's profile picture

    @jackisgeeky

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

    3 likes

  • Ray Epps's profile picture

    @rayeppsonx

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

    2 likes

  • JETLAB-X's profile picture

    @JETLABX

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

    2 likes

  • BullBear.News's profile picture

    @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 likes

  • Adrien Chauvet's profile picture

    @adrien_chauvet

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

    1 like

  • symbols's profile picture

    @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 like

  • Chris Ziomkowski's profile picture

    @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 like

  • Deepak's profile picture

    @HaXX0R

    hmm interesting.

  • Gustavo Rocambóli's profile picture

    @Floripa2006

    2026 bro no one cares anymore

  • 音GATO's profile picture

    @realRiverC

    void pointers, the real polymorphism

  • ᴅ ᴇ ᴀ ᴅ ʙ ᴏ ʏ's profile picture

    @DeadboyEzra

    Boy, you don’t want my ass multiplying.

  • Mēgan DeMarco's profile picture

    @Musk_Megan2026

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

  • Pitchfork & Torch ♞'s profile picture

    @SuddenlyJon

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

  • Clank's profile picture

    @clankenluben

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