SDL_copyp(3)

✨ SDL_copyp ✨

okay bestie, welcome to SDL_copyp β€” she's a macro from the SDL3 FUNCTIONS lineup and she is here to copy memory between objects with basic type checking, no cap πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

#define SDL_copyp(dst, src)                                                                 \
    { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); }             \
    SDL_memcpy((dst), (src), sizeof(*(src)))

πŸ’– DESCRIPTION πŸ’–

so like, SDL_memcpy and SDL_memmove? iconic, love them, but they literally do not care where you copy memory to and from 😭 and that is exactly how bugs get born. This macro's whole personality is avoiding most of those bugs by making sure the source and the destination are both pointers to objects that are the same size. That's it, that's the vibe.

ngl though β€” it does not check that the objects are the same _type_, only that the copy won't overflow either object. so yeah, same size β‰  same type, iykyk πŸ™ˆ

the size check happens at compile time, and the compiler will throw an error if the objects are different sizes. so you find out immediately, not at 3am in production. main character energy fr fr πŸ”₯

generally this is intended to copy a single object, not an array. just one. a singleton. a solo queen πŸ‘‘

and before you come for her: this macro looks like it double-evaluates its parameters, but the extras are all chilling inside sizeof sections, which generate no code nor side-effects. so it's giving double-eval but it's actually not. gaslight gatekeep girlboss ✨


πŸŽ€ MACRO PARAMETERS πŸŽ€

  • dst β€” a pointer to the destination object. Must not be NULL. 🚫
  • src β€” a pointer to the source object. Must not be NULL. 🚫

πŸ¦‹ THREAD SAFETY πŸ¦‹

It is safe to call this function from any thread. periodt. every thread, all at once, she doesn't care πŸ’œ


🌈 AVAILABILITY 🌈

This function is available since SDL 3.2.0. so if you're on something older... bestie, upgrade 🫢


okay that's the whole page!! πŸ’– source/version tea: this is Simple Directmedia Layer, SDL 3.4.18, and the page is SDL_copyp(3). mwah, go forth and copy safely β­πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from