C Programming on the Mac L46 - Variadic Functions

preview_player
Показать описание
How to create variable argument lists (variadic functions) in C. This allows you to have a varying number of parameters for your functions.

Рекомендации по теме
Комментарии
Автор

I mostly know C, except for Variadic functions. This was useful to me. Thanks.

Enter_channel_name
Автор

I hinted in the tutorial that my example wasn't great and in this you would rather just pass in an array of ints. Like I said, the 2 general use cases are with format strings (like printf) and with NULL or 0 termination. You can see examples of this when creating an NSArray or NSDictionary in the Objective-C series where you add your objects and then end with nil to specify the end of your list.

AppleProgramming
Автор

In a strange coincidence, I started picking at NSRuleEditor and the sample code has one of these in it for dealing with children of criterion. Thanks Lucas!

PhaedraDeepsky
Автор

Well you can if you have some object of type id (a generic object which we can assume adheres to the NSObject protocol). With type id we can ask it if it responds to selectors (covered in the Selectors tutorial). Also we can use the -isKindOfClass: or -isMemberOfClass: methods and then compare it to the class. For example [string isMemberOfClass:[NSString class]] -> returns YES or NO.

AppleProgramming
Автор

This is a great series. I really appreciate it. It's excellent. Thank you.

ALulzyApprentice
Автор

Hey Lucas. I really like your tutorials. I think you cover a lot of what's important. As far as retaining the information and putting the techniques into practice though, I find that after getting to this point I have trouble applying all that I've learned here thus far. I think it would be cool at the end of each video you gave a "practice problem" and posted the solution somewhere. Cheers!

matthewpoell
Автор

I haven't looked too much into it, but I would assume since everything is a pointer in Obj-C that it wouldn't be difficult to iterate through (I think they all have the same sizes since they are all just pointers).

AppleProgramming
Автор

True, but there are ways of determining the class type in Objective-C. NSArray probably has no idea what each object is. We can ask each object what class it is using the +class method or what methods the object responds to etc.

AppleProgramming
Автор

Well in C you would just use an array of ints as well as your parameter. I'll say that that the example I used isn't really a good one (I said that in the tutorial as well). The 2 main use cases are with format strings (printf) and NULL or 0 termination. You can see examples of this when creating an NSArray or NSDictionary in the Objective-C series where you add your objects and then end with nil to specify the end of your list. Sorry for the confusion on this.

AppleProgramming
Автор

But what about cout object in c++, how it knows the no. of variables that are going to be printed as unlike c it doesn't have format specifier?

princevijaypratap
Автор

Is there any way if we can pass variables args of different datatypes at the same time?

AbhishekKr
Автор

What I the huge benefit compared to passing an array of ints?

TomsonTheOne
Автор

C is so weird that it can't just know from the list when to terminate. You have to tell it explicitly. What happens if you didn't tell it, or lied to it?

adtc
welcome to shbcf.ru