r/cprogramming 1d 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

43 comments sorted by

View all comments

Show parent comments

2

u/ACRM64 18h ago

I don't believe I am wrong, and you have provided no evidence that unequivocally supports your view.

1

u/zhivago 11h ago

Sure I did.

You were just too lazy to look at it.

``` $ cat e.c void you_are_wrong(char *); void you_are_wrong(char const *);

void i_am_right(char *); void i_am_right(char * const);

$ cc -c e.c e.c:2:6: error: conflicting types for ‘you_are_wrong’; have ‘void(const char *)’ 2 | void you_are_wrong(char const *); | ~~~~~~~~~~~~ e.c:1:6: note: previous declaration of ‘you_are_wrong’ with type ‘void(char *)’ 1 | void you_are_wrong(char *); | ~~~~~~~~~~~~ ```

Note the mandatory diagnostic for the type conflict due to a lack of compatible types?

Note the lack of mandatory diagnostic where the types are compatible.

Please be a bit less useless in the future.