Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

Destructuring in C

Pankak
Pankak

I was wondering if destructuring is possible in C. Here's an example in pseudocode of what I'm thinking of:

void func({ int foo; int foo2; }){ } struct { int foo; int foo2; } victim;

Not particularly necessary but I recall finding something about this or something similar, which I can't find now.

@Coder100
@xxpertHacker
smert ppl halp

2 years ago
You are viewing a single comment. View All
1
xxpertHacker
xxpertHacker

@Pankak
Lmao, ofc it is, it's UB; I'm reusing the values that were still left on the stack to automatically fill x and y, but that is exactly how a destructuring operation would be compiled, just push some values to the stack, and use those as the variables, so at least it's performant. (btw, even -O1 will make this fail)

Btw, you probably heard that C# has destructuring, not C.

2 years ago