A masterful display of preprocessor wizardry that pushes C to its absolute logical limits. It is a brilliant example of a solution that is as intellectually impressive as it is practically terrifying to maintain.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
Recursive macros in CHinzugefügt:
Sup, guys.
Welcome to today's show.
So is it possible to count function arguments in C?
Let's say I have a function which I'm calling like this.
So something like this.
So this I want to return three.
And if we have a fourth argument, I want it to return four.
How do we do that?
We cannot do it with functions, that's for sure.
But perhaps we can do it with macros if we manage to make them recursive.
Let's try.
How do we do this?
Let's say let's make it easy.
Let's say that we have a null terminating function for now.
So if and if x is zero.
In that case, we want to return the arguments.
No, let's say we want to return the number of arguments.
Otherwise we want to return count with the current number of arguments plus one and and then the rest of the arguments.
So we peel off one argument at a time because we return Xs.
We do not return the first argument and the rest.
So this could actually work.
So how would we initialize such a thing?
We could do something like if we call this count, underscore first, and then we define the regular count, which only takes or is so Xs.
And this will return, underscore, count and start the recursion by.
So by providing the zero as the number starting number and and then providing the arguments like this.
So let's just to have something let's say we have let's create an integer data type.
So we say we have an unsigned SHA, which we call a, and here in a let's say number of we have an in a number of args, which is equal to count.
And then we have this a, B, C, like this.
Let's see what the preprocessor makes out of this.
First does it to even compile.
Oh, what happens if we run?
Let's see if we run c p, That's the C preprocessor.
So it translates this.
So if a is zero, we return zero.
Otherwise, count of zero plus one, B and C.
So this part seemed to work, but the preprocessor doesn't really like the we define this recursive word if we were to first define this as something else.
So let's say a, B, C, and the return zero or something.
This should compile like thing because this should be the same right?
We get a warning, that's really fine, but does it compile count as the same problem?
No implicit declaration of Why is an implicit declaration?
Because we we do define here.
Oh, so maybe because of the wrong number of arguments.
It's not. Hmm.
This, however, does make sense.
It's not the constant. So let's move this into here instead.
Stuck in here.
What if we were to do something like this?
So we define it with two argument works.
Let's define it like this.
And maybe just like this one.
But this.
It's an implicit declaration.
It does exist.
And the preprocessor itself makes the right thing out of it.
Is it possible to bypass the error or the.
Could we simply remove the this shit?
Hmm. What if we had a similar function but with a different name?
So let's say we have and we had the same problem here instead.
So we find this with this and this with this.
It's weird where it complains on the underscore count, but no, it's on the double underscore, I guess, because this is the first location.
How can we go around this?
Could we bounce like create a function?
Maybe.
So how would that look?
Something like in a town, the total.
All right.
Let's see what happens.
My actual count requires three arguments, but only one gives them.
That's right.
This needs to be above.
Okay.
It compiles.
That's interesting.
See, with Preprocessor says, like, if this is going to call this function, let's see if A is here, returns here was if B is the real returns zero plus one and zero plus one plus one.
So the idea were that we would probably need to have as many levels as there might be arguments.
Let's just try to add one more level.
So this would be code with three, right here calling the one with two to call and one with one.
Where am I going?
The wrong direction here.
The second calls underscore count, underscore, count.
Those two double underscore the below underscore goes to three and three would go to four.
Let's make the the fun so this expected expression isn't is basically what we did before we're just given a rule the country first this underscore count with this 12341234.
One, two, three, four.
Let's call this one f count instead the function count.
What does the c c preprocessor say?
Ethereal. Zero other words.
If this zero, then zero plus one and the C zero we have zero plus one +12, then zero plus one plus one.
Then use this and this other words you have if count of zero plus one plus one plus oh.
Is the argument because there's no argument left.
What if we were to just do this?
What would happen then?
Still the same problem.
So how do we deal with the.
So this is why I wanted to create my own C person pass through because it's so very limited.
The abilities in the Xs is nothing at this point.
Maybe we need to do this.
Yeah, we do.
I forgot about the node terminator, so that's really true.
We need to add every.
But that won't really help.
Will be let's.
Yeah.
Must actually work.
Let's try to print something like this too.
Pretty nice.
And what if we were to add the C here?
Then it goes to zero.
But if we have just one, then it goes to one.
Okay, so we need to have one more of these underscore macros than we need.
And then we have arguments.
So if we were to continue this, we would after a while have something that actually works.
It doesn't make the cleanest looking code, but but the general idea works.
And why do we need something like this?
Well, if we are able to do this kind of recursion, there's should be possible to to create a like a generic console.log log function similar to JavaScript.
So we don't have to deal with print death and format strings and kinds of variables.
We could just say print and whatever.
So maybe that will be the next step.
What do you think?
Could we do something other with this?
And besides, do you have a cleaner solution to this?
Please let me know.
And I really hope you like this episode.
Don't forget to like and subscribe and thank you for watching.
And for today.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











