azonenberg, to random
@azonenberg@ioc.exchange avatar

Finally got around to making a proper image version of the meme.

azonenberg, (edited )
@azonenberg@ioc.exchange avatar

class FaultDisabler
{
public:
FaultDisabler() { sr = SCB_DisableDataFaults(); }
~FaultDisabler() { SCB_EnableDataFaults(sr);}
protected:
uint32_t sr;
};

unsafe FaultDisabler fd;

nolanl,
@nolanl@mastodon.social avatar

@azonenberg Is that #define correct?

It looks like:
unsafe {
code();
}
expands to:
FaultDisabler fd; {
code();
}

and so the RAII object is outside the {} scope, and thus lives past the } and until the enclosing scope is exited...

psychicparrot42, to unrealengine
@psychicparrot42@mastodon.gamedev.place avatar

My instinct to capitalise the 'object' in 'sub object' keeps slipping me up when I use Unreal's CreateDefaultSubobject function. Gah! I want to capitalise the object SO MUCH!!! #UE5

JeremiahFieldhaven,
@JeremiahFieldhaven@mastodon.gamedev.place avatar

@psychicparrot42 #define CreateDefaultSubObject CreateDefaultSubobject

There you go!

(Please don't do this)

itchi5, to random
@itchi5@illo.social avatar

Bit of a morning dance.

#define #dancing

raodaozao, to random
@raodaozao@mastodon.gamedev.place avatar

Every day I find new ways to be surprised and "delighted" by Unity. Today: turns out that if a vector has a small enough magnitude, normalising it just returns... zero. Even if the magnitude isn't actually all that small. Thanks, Unity. Thunity. 😌

rep_of_a,
@rep_of_a@mastodon.gamedev.place avatar

@raodaozao @vfig I'm quite agressive in my my math code with epsilon, and unfortunatly the 10 years that past since I wrote all that I can't remember why, but almost certain its todo with comparisons.

#define ROA_EPSILON (0.0000001f)

if(vec3_equals_vec3(a,b)) {

}

Doomed_Daniel, to random
@Doomed_Daniel@mastodon.gamedev.place avatar

I'm not sure if everyone shares my fondness for X macros, but I sure like them:
https://github.com/DanielGibson/dhewm3/blob/a0bd8161445462daf6253da3ce9b7eeee5a64c89/neo/sys/sys_imgui.cpp#L516-L886

(that code writes and reads Dear ImGui styles to/from an ini-like text file)

Doomed_Daniel,
@Doomed_Daniel@mastodon.gamedev.place avatar

Huh, just realized that all X macro examples I could find use exactly one name for the entries (often "X") - I found using several for different purposes, like different member types to (de)serialize, very useful - is this really unusual or did I just not look hard enough?

Example:

#define D3_IMSTYLE_ATTRS \
D3_IMATTR_FLOAT ( Alpha ) \
D3_IMATTR_FLOAT( DisabledAlpha ) \
D3_IMATTR_VEC2( WindowPadding ) \
D3_IMATTR_INT( ColorButtonPosition )

etc

Doomed_Daniel,
@Doomed_Daniel@mastodon.gamedev.place avatar

(and then I #define D3_IMATTR_FLOAT(NAME), D3_IMATTR_VEC2(NAME) and D3_IMATTR_INT(NAME) however I need it to print/write or parse or whatever, before just putting "D3_IMSTYLE_ATTRS" in a line that then expands all that)

The X Macro examples/articles I found would instead probably use X(NAME, TYPE, SCANFSTR, PRINTFSTR) or sth like that instead of D3_IMATTR_FLOAT(NAME), D3_IMATTR_VEC2(NAME) etc, which would've been more painful overall, IMO

Doomed_Daniel,
@Doomed_Daniel@mastodon.gamedev.place avatar

Apart from this, I must admit I'm a bit proud of my hack to check if my table that mirrors a (thankfully continuous) enum is complete:

#define D3_IMSTYLE_COLOR(C) + 1

static_assert( ImGuiCol_COUNT == 0 D3_IMSTYLE_COLORS, "something was added or removed in enum ImGuiCol_ => adjust D3_IMSTYLE_COLORS table above" );

"0 D3_IMSTYLE_COLORS" is expanded to 0 + 1 + 1 + ... for each D3_IMSTYLE_COLOR entry

penguin42, to random
@penguin42@mastodon.org.uk avatar

I think I just found a #define unused in the Xserver since ~1996.

Python is great, but stuff like this just drives me up the wall (lemmy.world)

Explanation: Python is a programming language. Numpy is a library for python that makes it possible to run large computations much faster than in native python. In order to make that possible, it needs to keep its own set of data types that are different from python’s native datatypes, which means you now have two different...

danluu, (edited ) to random
@danluu@mastodon.social avatar

I can't quite put my finger on it, but there's something delightful about this list of "legitimate" uses of negative literals:

https://github.com/elm/compiler/issues/1773.

I think part of it is the circumstances that would compel users to construct such a list. Until that thread, it hadn't even occurred to me that someone would present a case against the existence of negative literals that required a rebuttal.

rygorous,
@rygorous@mastodon.gamedev.place avatar

@pervognsen @danluu It doesn't really work well to define it that way on two's complement targets though.

E.g. the canonical way to #define INT_MIN on 32-bit C targets is (-0x7fffffff - 1) or similar. You can't write (-0x80000000) since the 0x80000000 is too large for int32 so it forces the constant to be unsigned, and then you end up with the wrong type.

fubarx, to memes in Destroying friendship

MSVC supports unicode. In C or C++, you could try:

#define ; ;

Second one is the greek semicolon but the client I’m using may strip it out. I’m too lazy to try.

PM_ME_VINTAGE_30S, to memes in Destroying friendship
@PM_ME_VINTAGE_30S@lemmy.sdf.org avatar

Running ; anything yields error: macro names must be identifiers for both C and C++ in an online compiler. So I don’t think the compiler will let you redefine the semicolon.

PM_ME_VINTAGE_30S, (edited ) to memes in Destroying friendship
@PM_ME_VINTAGE_30S@lemmy.sdf.org avatar

Well I just tried #define int void in C and C++ before a “hello world” program. C++ catches it because main() has to be an int, but C doesn’t care. I think it is because C just treats main() as an int by default; older books on C don’t even include the “int” part of “int main()” because it’s not strictly necessary.

#define int void replaces all ints with type void, which is typically used to write functions with no return value.

lanodan, to random
@lanodan@queer.hacktivis.me avatar

We have ps(1) at home.
ps at home: grep . /proc/*/cmdline

lanodan,
@lanodan@queer.hacktivis.me avatar

Heck of a stub mount:

#define _GNU_SOURCE
<a class="hashtag" data-tag="include" href="https://queer.hacktivis.me/tag/include">#include</a> <sys/mount.h>
int
main() {
        return mount("/dev/sda", "/oasis", "ext4", 0, 0);
}

(Wrote it with ed(1), even if I likely could get vis at this point)

stungeye, to gamedev
@stungeye@mastodon.gamedev.place avatar

Created an example C++ project using the Simple DirectMedia Layer library () with Visual Studio on Windows.

https://github.com/stungeye/VSVcpkgSDL2

Uses for dependency management. Build instructions are at the bottom of the readme.

Good starter project if you want to try some low-level coding.

stungeye,
@stungeye@mastodon.gamedev.place avatar

@raptor85 Oh, thanks! This is great info. I used WinMain as a way of getting rid of the extra console terminal that was opening up along with the SDL window.

Also, when I had my own main() I got a compiler error that I could only get rid of by adding a SDL_MAIN_HANDLED before the SDL.h include. Is using that okay, or is there a better way?

uss_oatmeal, to random
@uss_oatmeal@mstdn.party avatar

@thephd Please tell me you got rid of #define in C23, yeah? Please, like for real, maybe?

Sigh, I'm trying to extract one function (and support) from the musl library and convert it into C#. I've been feeling fairly confident about it, though concerned about the volume of code and wondering if my original approach might be "good enough".

Still in an explorer mode, I found what looked like functions turn out to be a macro. NBD. Then a macro to a macro. Then 3 layers deep.

I'm crying.

lanodan, to random
@lanodan@queer.hacktivis.me avatar

So much of C portability is fucking around with #define _{DEFAULT,BSD,GNU}_SOURCE so that the things you want are visible…

navi,
@navi@social.vlhl.dev avatar

@lanodan me #define _XOPEN_SOURCE 500 so that nftw is visible but suddenly that breaks freebsd includes on ci bc setting a standard is supposed to hide the extensions ig

whitequark, to random
@whitequark@mastodon.social avatar

the DOS INT13 handler is doing getenv in debug builds?

SebastienLugan,
@SebastienLugan@mastodon.social avatar

@whitequark Reading this (curly braces replaced by BEGIN/END using a #define), I can't help but remember this awesome comment in fdisk.c 😄
https://github.com/microsoft/MS-DOS/blob/2d04cacc5322951f187bb17e017c12920ac8ebe2/v4.0/src/CMD/FDISK/FDISK.C#L51

Nibodhika, to asklemmy in Which programming languages do you know?

Só for example this in C/C++ #define true (__LINE__ % 10 != 0). Not sure if that counts as swear, but put that in a code and you’ll hear lots of swearing hahahahaha

lanodan, to random
@lanodan@queer.hacktivis.me avatar

GNU What The FUCK.

$ getconf _POSIX_NAME_MAX .
255
$ getconf _POSIX_PATH_MAX .
4096
$ qlist glibc | grep include | xargs grep -e _POSIX_NAME_MAX -e _POSIX_PATH_MAX
/usr/include/bits/posix1_lim.h:#define  _POSIX_NAME_MAX         14
/usr/include/bits/posix1_lim.h:#define  _POSIX_PATH_MAX         256
$ qfile -v `command -v getconf`
sys-libs/glibc-2.38-r12: /usr/bin/getconf

felsqualle, to random
@felsqualle@manitu.social avatar

Well... I wanted to look into compiling MS-DOS 4.0 after Microsoft released the sources today.

Looks like it won't compile from scratch because the conversion to git killed some characters and inlined byte-sequences :(

https://github.com/microsoft/MS-DOS/blob/main/v4.0/src/SELECT/USA.INF

shanselman,
@shanselman@hachyderm.io avatar

@felsqualle @starfrost ya that #define was hilarious to find

nixCraft, to random
@nixCraft@mastodon.social avatar
freevolt24,
@freevolt24@mastodon.social avatar

@nixCraft #define 💀 abort()

LianSirenia, to random
@LianSirenia@transfem.social avatar

Ya'll aught to be careful about how much you say I'm cute or awesome or whatever, keep this up and I might start actually believing it, can't imagine, honestly

KaitlynEthylia,
@KaitlynEthylia@akko.wtf avatar

@ielenia @MikeHar94962844 @LianSirenia Well this one should be pretty cursed

#include <stdio.h>

<a class="hashtag" data-tag="define" href="https://akko.wtf/tag/define" rel="tag ugc">#define</a> MSG "Lian is cuten"

int count() {
  static int c = 0;
  c++;
  return c % sizeof MSG;
}

int main() {
  char* msg = MSG;
  for(;count();msg++)
    putc(*msg, stdout);
  return main();
}
  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • thenastyranch
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • ngwrru68w68
  • provamag3
  • magazineikmin
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • JUstTest
  • All magazines