Live data from Hacker News

C-Macs – a pure C macOS application

github.com

31–40 of 138 posts

Re: C-Macs – a pure C macOS application

#31
post #30

I 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.)

The 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

The 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.

Re: C-Macs – a pure C macOS application

#32
post #9

Earlier quoted context omitted.

MacOS apps are typically written in either Objective-C or Swift as these are the officially supported languages for the MacOS APIs. The code in this template is interfacing with the Objective-C runtime but with pure C.

Does this mean that, theoretically, this could lead to the ability to build MacOS apps in higher languages that interoperate well with C such as Python? I know you can build MacOS apps with Python now, but does this potentially improve the experience?

I believe RubyMotion does basically this:

http://www.rubymotion.com

It was fun building an app in this a few years ago, but was difficult to keep up with updates to MacOS breaking my code.

Re: C-Macs – a pure C macOS application

#33
post #11

Love this, if I never have to write a wrapper around objc again I'd be in heaven.

This 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.

Re: C-Macs – a pure C macOS application

#34
post #6

As 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.

> why this is significant? Ultimately, because new people keep being born and missed the years where this was pretty common and haven't yet bumped into the corners where it still is. The repo and the SO discussion it was inspired by are themselves 11 years old and seem to be rooted in a new generation of iOS app developers starting to get more deeply curious about the system they're running on and how else it might b…

This isn’t an example of that. Have you looked at the code? This uses ObjC and Cocoa implementations in an unintuitive method. Nice exercise to learn about the ObjC runtime, but has zero practicality or use.

Re: C-Macs – a pure C macOS application

#35

Earlier quoted context omitted.

I’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.

It'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... 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…

Copyleft licenses depend on copyright. I think it was in an FSF FAQ somewhere. GPL is as copyright maximalist as it gets.

Re: C-Macs – a pure C macOS application

#36
post #30

Earlier quoted context omitted.

The 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

The 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.

The OP says it is Cocoa-less in the readme, is that not true?

Re: C-Macs – a pure C macOS application

#37

Earlier quoted context omitted.

That has always been possible. Also, under the ObjC layer, is good ol' ANSI C (FreeBSD Unix). There's a number of apps that run on modern Macs, that were written in C, but it is unusual to see ones that leverage the GUI. That said, it's possible to walk from Boston to Portland (OR), but I'd rather take a plane.

It has, but there was also Carbon until around the Intel transition.

Full Carbon was there until the 64bit transition officially, but much of it remained and still remains until now. For example, Apple only started using AppKit to draw menus in Sonoma; it was Carbon until now.

Re: C-Macs – a pure C macOS application

#38
> 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#...

Re: C-Macs – a pure C macOS application

#39

Earlier quoted context omitted.

The 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.

The OP says it is Cocoa-less in the readme, is that not true?

It'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.
Post reply on HN