863
you are viewing a single comment's thread
view the rest of the comments
[-] perviouslyiner@lemmy.world 241 points 7 months ago* (last edited 7 months ago)

define it as ( __LINE__ % 10) so that the problem goes away when you add a debug statement

[-] Prunebutt@slrpnk.net 41 points 7 months ago

Can someone ELI5 what this does?

[-] tunawasherepoo@iusearchlinux.fyi 29 points 7 months ago

__LINE__ returns the line of code its on, and % 10 means "remainder 10." Examples:

1 % 10 == 1
...
8 % 10 == 8
9 % 10 == 9
10 % 10 == 0 <-- loops back to 0
11 % 10 == 1
12 % 10 == 2
...
19 % 10 == 9
20 % 10 == 0
21 % 10 == 1

In code, 0 means false and 1 (and 2, 3, 4, ...) means true.

So, if on line 10, you say:

int dont_delete_database = true;

then it will expand to:

int dont_delete_database = ( 10 % 10 );
// 10 % 10 == 0 which means false
// database dies...

if you add a line before it, so that the code moves to line 11, then suddenly it works:

// THIS COMMENT PREVENTS DATABASE FROM DYING
int dont_delete_database = ( 11 % 10 );
// 11 % 10 == 1, which means true
load more comments (7 replies)
load more comments (17 replies)
this post was submitted on 09 Feb 2024
863 points (97.6% liked)

Programmer Humor

19198 readers
2050 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS