Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between typeof, __typeof and __typeof__ in Objective-C

Tags:

objective-c

In Objective-C I often use __typeof__(obj) when dealing with blocks etc. Why not __typeof(obj) or typeof(obj).

When to use which?

like image 332
hfossli Avatar asked Feb 14 '13 14:02

hfossli


1 Answers

__typeof__() and __typeof() are compiler-specific extensions to the C language, because standard C does not include such an operator. Standard C requires compilers to prefix language extensions with a double-underscore (which is also why you should never do so for your own functions, variables, etc.)

typeof() is exactly the same, but throws the underscores out the window with the understanding that every modern compiler supports it. (Actually, now that I think about it, Visual C++ might not. It does support decltype() though, which generally provides the same behaviour as typeof().)

All three mean the same thing, but none are standard C so a conforming compiler may choose to make any mean something different.

like image 197
Jonathan Grynspan Avatar answered Sep 28 '22 05:09

Jonathan Grynspan