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 beNULL. π«srcβ a pointer to the source object. Must not beNULL. π«
π¦ 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms