6 ms·
> The ability to use a high-level, dynamic language (ObjC), C, and even inline assembly in a single source file is unique to Objective-C (at least among the "ma
by conradev 11y ago
> The ability to use a high-level, dynamic language (ObjC), C, and even inline assembly in a single source file is unique to Objective-C (at least among the "mainstream" languages), and something I think is often under-appreciated.
You can even use C++, too, which is awesome. Putting Objective-C objects in C++ structs "just works" thanks to ARC.
One thing most people don't know is that Objective-C was originally implemented as a precompiler for C.
- dep_b 11y agoI think it actually was a precompiler for C up til a point. Still Objective-C objects have underlying C functions that are being called whenever you try to call a method or anything on an Objective-C object. Theoretically you should be able to call functions on Objective-C objects from C.
- conradev 11y ago> Still Objective-C objects have underlying C functions that are being called whenever you try to call a method or anything on an Objective-C object. The same goes for C++ or Swift. Getting the function pointer for a method can be involved, but all functions adhere to the C ABI.
- poizan42 11y agoAt least MSVC on x86 uses "thiscall" by default which puts the this pointer in ecx. You cannot call those functions from C without specific compiler support.
- vardump 11y agoSure you can. Just write an asm stub to call, that sets up ecx and other things right.
- poizan42 11y agoThe claim was: The same goes for C++ or Swift. Getting the function pointer for a method can be involved, but all functions adhere to the C ABI. This is clearly false since at least one C++ compiler generates functions that does not adhere to any of the common calling conventions for C on that platform (or "C ABIs" if you will). Besides that, I said you could not call them from C. An asm stub is not C. Neither is inline assembly even though it's a common extension to C.
- jheriko 11y agothats not true if you inspect the details of the specific ABI and cheat a little or use some inline assembler... but cl is easily the worst compiler for a C++ ABI. they break it on tiny incremental updates sometimes... at least historically (in fairly recent history at least).
- poizan42 11y ago> thats not true if you inspect the details of the specific ABI and cheat a little or use some inline assembler... Some x86 C compilers supports calling conventions that lets you put things in registers, e.g. Microsofts "fastcall". But I wouldn't consider that part of the standard "C ABI" for Windows given that it's practically never used for externally visible functions. As I said "without specfic compiler support". Using inline assembler is just cheating, it's not C. > but cl is easily the worst compiler for a C++ ABI. they break it on tiny incremental updates sometimes... at least historically (in fairly recent history at least). That is more about name mangling schemes and layout of standard library classes though. As far as I know the calling conventions has been quite fixed for a long time.
- chris_wot 11y agoWhat C ABI? Can you point me to the spec?
- deathanatos 11y agoI don't believe C standardizes the ABI across all OS/hardware combinations. But some OS/hardware combinations are standardized; for example, there's the AMD64 ABI[1], which I think just about every operating system that runs on amd64 uses … except Windows. [1]: http://www.x86-64.org/documentation/abi.pdf http://www.x86-64.org/documentation/abi.pdf
- chris_wot 11y agoYeah, but that's a bit of a long bow... That's not a C ABI :-)
- valarauca1 11y agoObjective-C was a modification of the GCC developed by NeXT. NeXT didn't publicly release their patches and the FSF/GNU threatened legal action. NeXT released their sources and the GCC now supports Obj-C. Source: https://en.wikipedia.org/wiki/GNU_General_Public_License#Legal_status https://en.wikipedia.org/wiki/GNU_General_Public_License#Leg...
- conradev 11y agoMore details: > In order to circumvent the terms of the GPL, NeXT had originally intended to ship the Objective-C frontend separately, allowing the user to link it with GCC to produce the compiler executable. After being initially accepted by Richard M. Stallman, this plan was rejected after Stallman consulted with GNU's lawyers and NeXT agreed to make Objective-C part of GCC. Source: https://en.wikipedia.org/wiki/Objective-C#Popularization_through_NeXT https://en.wikipedia.org/wiki/Objective-C#Popularization_thr...
- msbarnett 11y ago> Objective-C was a modification of the GCC developed by NeXT. No. Objective-C was developed in the early '80s (as a C pre-processor, as the Grandparent post said) by Brad Cox, and commercialized by himself and Tom Love via a company they created together called Stepstone. Cox wrote a book about their product, Object Oriented Programming: An Evolutionary Approach, in 1986. I own a copy. It's pretty good! Some time later, NeXT decided to build their user-space APIs around Objective-C, and bought the rights to Objective-C from Stepstone outright. It was at that point that they started modifying GCC to directly compile Objective-C rather than pre-process it into C.
- pixelglow 11y agoI have the book too. It's interesting as a history lesson and initial motivations for Objective-C. In particular, in the beginning Objective-C was a lot looser typed at compile time than it is now: no NSString* or NSWindow*, it was all just id. It was an attempt to make C look like Smalltalk. The language eventually evolved more toward the static-typed end of the spectrum, culminating in support for lightweight generics and ostensibly birthing Swift along the way.
- jheriko 11y agoyou mean objective-c++? c++ has no idea about obj-c... another thing most people forget is that the entire programming community rejected obj-c as deficient in its very early days... it only persists thanks to the ego of former nextstep employees afaik. and now apple employees got lumped with it... which i'd suspect helped create the internal pressure for swift... so some good came at the end of it all. :)
- astrange 11y agoObjective-C was the major inspiration for Java - you'll notice how little it looks like C++ - and therefore C# and co, so it's been very influential ever since the 90s. It's not worth listening to anyone who dislikes Obj-C just because of the [] syntax, which doesn't matter after the first 48 hours.
- _asummers 11y agoThis about mirrors my opinions about Objective-C. http://twistedoakstudios.com/blog/Post8237_a-years-worth-of-opinions-about-objective-c http://twistedoakstudios.com/blog/Post8237_a-years-worth-of-...
- astrange 11y ago> Lastly, neither has generic types. Not true anymore; ObjC has generics with type erasure. (But not all the cases can be exported to Swift.) > Instead, Objective-C has nil, which is like null except it won’t stop the program when you accidentally use it. That's… not quite right… but I guess he has the visible effects down. Anyway, ObjC has nullability annotations now for this. > For example, in Objective-C many objects have both a “core foundation” form and a “new style” “NeXTSTEP” form This is not legacy baggage, it's an intentional C bridge. > This is justified by conventions strongly favoring you not catching exceptions, and apparently the speed benefits are non-negligible, but it still blows my mind that Apple has their language default to incorrect behavior. He shouldn't use ARC+exceptions, because Cocoa itself is not exception-safe. Just quit the app if you get one.
- 11y ago
- kjs3 10y ago"One thing most people don't know is that Objective-C was originally implemented as a precompiler for C." Same with C++ (see: AT&T 'cfront')