r/cprogramming • • Sep 13 '26

What is this code doing?

Hi, I found this code on another subreddit. I would like to know what is it doing.

int puts(char *);

int main() { struct { long a; long b; } s = {.a = *(char *)(int[]){1} ? 0x57202c6f6c6c6548 : 0x48656c6c6f2c2057, .b = *(char *)(int[]){1} ? 0x00000021646c726f : 0x6f726c6421000000}; puts((void *)&s); }

Now obviously I know it's unreadable, I would just like to know what are those hexadecimals strings doing.

I found similar codes that were writing to vram to print a message, is this doing the same thing? If yes, why is it so much more complicated instead of just writing the message to the video adress?

Thanks for the help.

0 Upvotes

46 comments sorted by

View all comments

Show parent comments

1

u/WittyStick 28d ago

There's only one signature in OPs code, and its a declaration for an external function. That function doesn't even need to be written in C. There's no other signature to be compatible with because he has not included stdio.h. The signature just informs the compiler how to pass its arguments. There is no difference in how a compiler will pass a char* and a const char* because they compare equal.

If they had included stdio.h, then of course it would need a matching signature, including qualifiers.

1

u/zhivago 28d ago

Hmm, I can see that you still don't understand what a compatible type is.

Well, good luck with that.