memesearch
C Addition Function Hack

C Addition Function Hack

Download Find similar pictures
Text on the meme
finally worked out how to make a function for addition. C isn't as hard as people say ; cat add.c #include <stdio.h> #include <stddef.h> int add(int m, int n) { struct add { char a[m]; char b[n]; char c; }; return offsetof(struct add, c); } int main(void) { printf("%d\n", add(2, 3)); return 0; } ; cc add.c ; ./a.out 5
What it means

A programming post shows a supposedly simple C function for addition, but the code abuses struct layout and offsetof to calculate 2 + 3. The joke is that the author claims C is easy while using an unnecessarily complicated and obscure trick to print 5. It is shared as a reaction to overengineering a simple programming task.

Objects
Tags
Sources
Type
image
Size
558×800 · 48.6 KiB
Mood
sarcastic
Language
en
Added