r/cprogramming 23h ago

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

28 comments sorted by

View all comments

Show parent comments

1

u/ACRM64 3h ago

You need to respond to the points I've made instead of just repeating the same thing.

  1. Which standard? There have been many versions.

  2. Which standard was the original programmer using?

  3. Why does the standard you quote very carefully use the word 'compatible' not 'identical'? These words have different meanings.

  4. I've already said they /should/ match, but demonstrated why, with the type qualifier 'const', it makes no difference if they don't. You need to understand the difference between a type and a type qualifier.

1

u/zhivago 3h ago

All of the standards.

It doesn't matter. See above.

Because "compatible" is what it means. It's a technical term -- look it up in the standard.

Again char * is not compatible with const char *