11 ms·
C-Macs – a pure C macOS application
- magicmicah85 3y agoGood example of digging with a spoon as they stated was the original goal. And it still compiles on an M1 macbook despite being a decade old code base.
- trenchgun 3y agoReally? Thats awesome, and unexpected! Got to try it out today then.
- beardedwizard 3y ago[flagged]
- codazoda 3y agoNo license typically means copyright with all rights reserved in the U.S. Perhaps you want to release this into the public domain (see SQLite)?
- actionfromafar 3y agoI’d say the license is: “ Use it at your own risk, and don't blame me if anything bad happens. Oh, and if you extend it, make sure there isn't any Objective-C in it!” I’d classify it as Open Source.
- nicky0 3y agoOh no that won't fly at all. People around here really like "proper" licenses. And they'll tell you about it.
- actionfromafar 3y agoI don't like the (perhaps actually a) license, because it set's limits on what the user can do with the source code. (Not allowing Objective C in it.)
- fao_ 3y agoyeah i accidentally added objective c code and now im kissing my ass bracing for the lawsuit!!!!!!!111
- gleenn 3y agoI'm not a lawyer but one would definitely let you know that at least in the US, software without a license is more dangerous than software with even a very restrictive one. Someone can come along and determine the license at any time. So there is good reason to point it out unless you crave legal jeopardy.
- nicky0 3y agoGNU/FSF's opinion on informal licenses (https://www.gnu.org/licenses/license-list.html#informal https://www.gnu.org/licenses/license-list.html#informal): Informal license An “informal license” means a statement such as “do whatever you like with this” or “you can redistribute this code and change it.” In the United States, these licenses are supposed to be interpreted based on what the author seems to intend. So they probably mean what they appear to mean. That would make them non-copyleft free software licenses and compatible with the GNU GPL. However, an unlucky choice of wording could give it a different meaning. However, many other countries have a more rigid approach to copyright licenses. There is no telling what courts in those countries might decide an informal statement means. Courts might even decide that it is not a license at all. If you want your code to be free, don't invite gratuitous trouble for your users. Please choose and apply an established free software license. We offer recommendations that we suggest you follow.
- williamcotton 3y agoIt's open source but it is still under copyright. There are notices in the source file: https://github.com/CodaFi/C-Macs/blob/master/CMacs/View.c#L5-L6 https://github.com/CodaFi/C-Macs/blob/master/CMacs/View.c#L5... I would definitely ask permission and encourage the author to change the license before using this code. Since API calls are purely functional and not covered by copyright you can mimic the behavior here but you'll need to rewrite everything from scratch, notably the most expressive parts, which are: https://github.com/CodaFi/C-Macs/blob/master/CMacs/CMacsTypes.h https://github.com/CodaFi/C-Macs/blob/master/CMacs/CMacsType... https://github.com/CodaFi/C-Macs/blob/master/CMacs/CMacsTypes.c https://github.com/CodaFi/C-Macs/blob/master/CMacs/CMacsType... The organization and structure of this code is arbitrary and within the author's creative expression.
- actionfromafar 3y agoIn most jurisdictions almost everything is under copyright, until it expires. (Which is approximately right before the heat death of the universe, after Disney get their way. Or 70 years after the authors death, or something like that.)
- ranger_danger 3y agohttps://arstechnica.com/tech-policy/2021/04/how-the-supreme-court-saved-the-software-industry-from-api-copyrights/ https://arstechnica.com/tech-policy/2021/04/how-the-supreme-...
- ngcc_hk 3y agoActually Micky is free.
- numpad0 3y agoCopyleft licenses depend on copyright. I think it was in an FSF FAQ somewhere. GPL is as copyright maximalist as it gets.
- williamcotton 3y agoI always see the strangest fluctuations in upvotes and downvotes whenever I state the laws and doctrines of copyright. FWIW, I do court ordered code inspections to assess alleged copyright infringement for a living.
- embirico 3y agoI do love the vibe of that license
- actionfromafar 3y agoIf it weren't for it claiming to not be a license in the sentence before, it would be pretty good. Reminds me of the WTFPL license. :) https://directory.fsf.org/wiki/License:WTFPL https://directory.fsf.org/wiki/License:WTFPL
- dec0dedab0de 3y agoIt’s definitely not Open Source with that Objective-C restriction. Though it does fit the attitude of the project.
- deleted 3y ago[deleted]
- 9dev 3y agoAs someone with no experience in native application development, could someone explain to me why this is significant? I have a rough idea, but I would like to understand it properly.
- jojobas 3y agoI guess it's normally impossible to write a GUI application for mac os without objective-c libraries doing the talking to the OS, but what do I know.
- swatcoder 3y agoIt is not. This was just a new wave of people finally looking under the hood. (Where they would have found many many dusty but detailed man pages and docs waiting for them)
- astrange 3y agoYou can write one in X11 if you like, if you make people install Xquartz.
- ngcc_hk 3y agoIs there example how to do that on mac. Just happy to have an old emu ibm 5100 sun x program. Wonder I need to boot up a vm or can try squartz …
- jmb99 3y agobrew install --cask xquartz Or install from the project homepage [1]. Then just launch the X11 app. Note that it does require the application to be built for Mac - it’s not an emulator, just an implementation of the X11 APIs. [1] https://www.xquartz.org/ https://www.xquartz.org/
- steve1977 3y agoBeneath Cocoa are Core Foundation and things like Core Graphics for example, which both are C.
- chunsj 3y agoIt seems that the code is the result of the ObjC preprocessor. :-)
- CodeWriter23 3y agoI know humor is not allowed on HN but lol
- chunkyguy 3y agoThere's also `clang -rewrite-objc` that "Rewrite Objective-C source to C++" which does the same trick of mapping objc code to `objc_msgSend` https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-rewrite-objc https://clang.llvm.org/docs/ClangCommandLineReference.html#c...
- rdrsss 3y agoLove this, if I never have to write a wrapper around objc again I'd be in heaven.
- LeoNatan25 3y agoThis uses the ObjC runtime to obtain the underlying ObjC method implementation functions, to call directly, instead of relying on the runtime to call them. If you find this more elegant than a wrapper with some ObjC, good for you.
- icedchai 3y agoI find Objective C more pleasant to use than C++. Maybe I'm crazy.
- JKCalhoun 3y agoI did a straight C++ app for MacOS but 1) I used SDL2 and 2) it was a full-screen game so no Cocoa UI needed. It was kind of fun though in a retro-computing way. (I'm a big fan of SDL now.)
- jonhohle 3y agoDon’t people do that all the time with Qt?
- deleted 3y ago[deleted]
- speps 3y agoThe linked project doesn't use any ObjC files at all. SDL2 has a bunch of Cocoa files[1] so you did use Cocoa even if unknowingly. [1] https://github.com/libsdl-org/SDL/tree/main/src/video/cocoa https://github.com/libsdl-org/SDL/tree/main/src/video/cocoa
- LeoNatan25 3y agoThe linked project also uses Cocoa, and guess what, considering Cocoa itself is written in ObjC, the linked project also uses OBjC “unknowingly”. Considering CodaFi works for Apple now, he knows. Spoiler: he knew 11 years ago too.
- anamexis 3y agoThe OP says it is Cocoa-less in the readme, is that not true?
- electroly 3y agoIt's not. Open up any of the .c files and you'll see lots of references to Cocoa. One of the comments refers to Cocoa by name! This is using objc_msgSend to call into Cocoa. You'd have to squint your eyes pretty hard for the claim in the readme to be true. What it doesn't have is Objective-C code, which is different than not having Cocoa.
- cnity 3y ago> A little bit of this also has to do to stick it to all those Luddites on the internet who post "that's impossible" or "you're doing it wrong" to Stack Overflow questions... Requesting permissions in the JNI "oh you have to do that in Java" or other dumb stuff like that. I am completely uninterested in your opinions of what is or is not possible. This is computer science. There aren't restrictions. I can do anything I want. It's just bits. You don't own me. From the wonderful CNLohr's rawdraw justification[0]. I always enjoy these kinds of efforts because they embody the true hacker spirit. This is Hacker News after all! 0: https://github.com/cnlohr/rawdrawandroid?tab=readme-ov-file#why https://github.com/cnlohr/rawdrawandroid?tab=readme-ov-file#...
- wil421 3y agoI like this guys spirit. Once I had to pick up old code from a guy with this spirit and it was f-ing horrible.
- mtillman 3y agoI love this project (from 2014?) and perhaps my favorite part other than the f-u of the whole thing is the commit message "complete refactoring".
- shrimp_emoji 3y agoBeats using Java Think of it as exercise: it sucks up front but you won't end up an obese diabetic on the WALL-E ship later.
- SpaghettiCthulu 3y agoJava is only a nightmare when you have to follow corporate decade-old "best" practices
- bheadmaster 3y agoIn my experience, Java is a nightmare the moment you try to do anything beyond what C++ can (easily) do.
- jbverschoor 3y agoThis would've been a lot easier to wrap my head around when I had to work with Objective C for the first time
- flohofwoe 3y agoHere's something similar by Garrett Bass: https://github.com/garettbass/oc https://github.com/garettbass/oc ...I also experimented a bit with parsing macOS system headers via clang-ast-dump and then code-generating C and Zig bindings but that didn't get far: https://github.com/floooh/objc-ast-experiments https://github.com/floooh/objc-ast-experiments ...with a bit of effort and maybe using libclang instead of clang-ast-dump that's definitely feasible though. I guess a similar approach is used by the official C++ bindings for Metal: https://developer.apple.com/metal/cpp/ https://developer.apple.com/metal/cpp/ ...also shameless plug: the sokol headers allow to write simple macOS applications (just a Metal canvas in a window) in various non-Apple languages (currently C, C++, Zig, Rust, Odin, Nim): https://github.com/floooh/sokol https://github.com/floooh/sokol ...I'm cheating though and use ObjC under the hood to talk to Cocoa and Metal ;)
- dgellow 3y agoI found this repo while looking for an equivalent to Win32 hello world[0] as a learning exercise during a long flight (with my work MacBook instead of my personal Windows machines). That's something I really like about Windows APIs — I can pick a new programming language I want to play with, as long as there is a way to interface with C I can try to port the Win32 hello world then play around. 0: https://learn.microsoft.com/en-us/windows/win32/learnwin32/your-first-windows-program https://learn.microsoft.com/en-us/windows/win32/learnwin32/y...
- tredre3 3y agoThe WIN32 API is somewhat ugly. I hate how all types are capitalized and their short abbreviations in arguments are sometimes weird. I hate how they have their own version of lots of standard C types that you have to be careful about (they weren't standard at the time, to be fair). But it's quite straightforward and easy to use. Any language that has FFI can call into it and build GUI apps, I've made a windowed Hello World in PHP with it. And it has been that way for 30+ years at this point. It's quite remarkable, really!
- dgellow 3y agoAlso, UTF-16 (or WTF-16 as defined by https://simonsapin.github.io/wtf-8/#wtf-16 https://simonsapin.github.io/wtf-8/#wtf-16)
- QuercusMax 3y agoI remember ages ago when I was about 12, I got a copy of Turbo C++ for Windows 3.1 for my birthday. (I had only written in Basic before, and wanted to learn a "real" programming language. My dad was a Fortran programming physicist, and had heard that C++ was what everyone was using then-a-days.) I mostly wrote simple console programs, and it came with the Borland ObjectWindows library with a fun GUI builder, but there was a section in the manual talking about how to write directly using the Windows API. I didn't really understand any of what I was reading, but I typed in the whole basic sample complete with HWNDs and all that nonsense. I can't remember if I could even get it to compile, but the idea of an event-loop was beyond my comprehension as a 12yo. I'm sure if I went back it would make a lot more sense to me, but back in 1994 it seemed like dark magic, especially compared to the much simpler and more understandable OWL components.
- cossinle 3y agoCrazy that this has to be a thing .. Why does Objective C even exist anyways??
- astrange 3y agoBecause Brad Cox liked Smalltalk.
- w10-1 3y agoDraw a line through this 12+-year-old effort from Robert Widmann and his 8-year-old exercise in type-lifting Swift [1] and ask yourself: what is he doing now at Apple? [1] https://github.com/typelift/Swiftz https://github.com/typelift/Swiftz
- saagarjha 3y agoYou can peek at his GitHub
- vineek 3y agoVery nice. In similar fashion, a few years back I set out to create Wuhoo. Wuhoo loosely stands for W indows U sing H eaders O nly. It is an attempt to create a single-header library (in the spirit of STB) for graphics related window management, compatible with both C and C++. It works on Windows, Linux and Mac. https://github.com/ViNeek/wuhoo https://github.com/ViNeek/wuhoo
- ks2048 3y agoThis would seem more complete if it had a simple Makefile rather than an xcodeproj.
- deleted 3y ago[deleted]
- cornstalks 3y agoIf you want to optimize this (and you enjoy pain), you can eliminate the dependency on objc/* headers and use compiler attributes and link sections to compile your code to the same(ish) assembly that Objective-C compiles to. I don't have a C example on hand, but here's a Rust example that's pretty easy to translate to C: https://github.com/objrs/objrs/blob/master/HOW_IT_WORKS.md https://github.com/objrs/objrs/blob/master/HOW_IT_WORKS.md
- MaxLeiter 3y agoFor an iOS attempt, I've often gone back to this wonderful StackOverflow post: https://stackoverflow.com/a/10289913 https://stackoverflow.com/a/10289913
- lapcat 3y agoThis app uses objc_msgSend, which feels a lot like cheating, but if you simply want to avoid using nibs (while still using Objective-C or Swift), check out my NiblessMenu project and my "Working without a nib" blog series. https://github.com/lapcat/NiblessMenu https://github.com/lapcat/NiblessMenu https://lapcatsoftware.com/articles/working-without-a-nib-part-11.html https://lapcatsoftware.com/articles/working-without-a-nib-pa...
- krackers 3y agoYou can probably do a "true" pure C application (as in no Cocoa at all and no linking to objc-runtime) by dropping down to the CoreGraphics layer, but a lot of it is undocumented. There's also Carbon (which I always assumed directly hit the same underlying quartz apis), but that's long deprecated and iirc never supported the UI portions in 64-bit
- cellularmitosis 3y agoI just Ed to say thank you for keeping your nibless posts from 2007 online. Handy for those of us doing a bit of retro computing on Tiger and Leopard. https://forums.macrumors.com/threads/developing-for-tiger-and-leopard-powerpc-a-devlog.2383838/ https://forums.macrumors.com/threads/developing-for-tiger-an...
- KerrAvon 3y agoSeeing some confusion. This is using what are effectively FFI interfaces to the Objective-C runtime. There’s really no good reason to do this in production code that isn’t a language bridge. It’s not as efficient at runtime as writing the functionally equivalent Objective-C, because the ObjC compiler statically allocates class/method data structures, and it’s not as safe, because you’re bypassing ARC.
- hgs3 3y agoIt would be nice to have something like this except for Metal. I'm unsure why Apple made Metal an Objective-C API when C + Core Foundation would suffice. One big advantage of a C API is it's easy to interop with other programming languages.
- AceJohnny2 3y agoApple is opinionated about which languages should be used on their platforms, and they enforce it with these kinds of decisions. For example, there was a time where Steve Jobs threatened to forbid iPhone apps not written in Obj-C, which would have destroyed the cross-platform ecosystem, at Apple's expense. Luckily, he was talked down from being that extreme.
- extraduder_ire 3y agoIs there any way to enforce that in a way that can't be worked around with a shim? Demanding source code? Looking for signs of other languages in the binary and not allowing them in the appstore if detected?
- AceJohnny2 3y agoI suppose the difficulty of proving that, short of demanding source code, helped prevent it from happening.
- jsjohnst 3y ago> Is there any way to enforce that in a way that can't be worked around with a shim? You can’t definitively prove something was written in Objective-C or Swift, but you can often definitively prove something was not written in either pretty easily just by looking at the assembly.
- eyesee 3y agoReminds me of an app I built ~20 years ago now. We wanted a cross-platform C++ layer and native Cocoa front end. Objective C++ wasn’t a thing then, and having built a plain C shim previously I didn’t want to repeat the experience. We built our own bridge by registering our C++ classes with the Obj-C runtime, generating selectors for all the methods so you could send messages to (carefully constructed) C++ objects using Obj-C syntax, or even subclass from C++ to Obj-C. It was a pretty neat trick, but would’ve been difficult to port to the Obj-C 2 runtime.
- slmjkdbtl 3y agoYou don't need a xcodeproj at all for a pure C macOS application (or do you need it 10 years ago? I see the last commit is 10 years)
- userbinator 3y agoUses under 1.5 MB of memory at any one time (most of it is used for drawing the window). Unfortunately there is no screenshot and I have no access to a Mac at the moment, but if View.c is where things actually happen, that is a huge amount of memory just for a (resizeable?) window with a little filled rectangle in it. The memory usage of a trivial app like this should be measured in kilobytes. Comparing applications written in the same language across platforms is IMHO a good gauge of their relative efficiency. From what I've seen, Win32 and Linux (Xlib) are pretty close but Mac is clearly very "think different". I'm sure the liberal use of string constants here doesn't help either. Here's a related interesting comparison: https://zserge.com/posts/fenster/ https://zserge.com/posts/fenster/
- joshstrange 3y ago> Unfortunately there is no screenshot and I have no access to a Mac at the moment, Here is a picture: https://cs.joshstrange.com/VSgrY06f https://cs.joshstrange.com/VSgrY06f
- eschaton 3y agoIt also depends on how the operating system and frameworks actually work. For instance, the backing store for the window may be “charged to” the application on macOS but may be provided by the OS on another platform, or there may not even be one.
- deleted 3y ago[deleted]
- quelsolaar 3y agoWe used the same technique to port our C applications to Apple platforms, but to do so we wrote an automated tool that created a C wrapper for any cocoa API we need. It works on all current Apple platforms we have tried it on iOS,iPadOS, and Apple Silicon Macs. Its open source: https://felixk15.github.io/posts/c_ocoa/ https://felixk15.github.io/posts/c_ocoa/
- eschaton 3y agoThis is basically what Go PenPoint programming was like. When you read the Go documentation it’s very clear they intended to use Objective-C or an equivalent preprocessor; I suspect they were stymied by NeXT’s acquisition or Stepstone and their own lack of support for GNU C.