C Language Support or Only C++ in Gtk 4.0

Hi all,

I realize C is a bit of a subset of C++. I also realize classes make polymorphism, inheritance, and a host of other things possible, including more disciplined variable use, etc.

Is it relatively easy to stick with C programming logic while developing with Gtk 4.0?

I had a lovely experience with Gtk 3.0, however I used my favorite programming language.


p.s. I realize I will have to port my app so that it uses Gtk 4.0 commands, however I would rather not have to convert all the code from C to C++.

Background: I personally, never warmed up to C++, despite having it forced on me in school. Many of us who tried to follow the rules and do everything in C++ (as the instructor said was required) got much lower grades than those who just used C programming in the final project.

GTK 4 is still written in C like it was for GTK 3. Why do you think you’d have to switch to C++ for it?

Good point.

I recently saw an ‘ad’ for Gtk 4.0 which boasted multiple language support including: C++, Python, Javascript, etc. Yet, C was not mentioned.

In the example(s), I saw only C++ code with all the usual (dreaded on my part) references to ‘protected’ vs ‘public’ vs ‘private’, references to instantiation procedures, etc.

All for a simple ‘hello world’ example.

Thanks for your input!

I fear (despite all my efforts to build a nice Gtk 3.0 app using the C programming language, I will have little choice but to switch to something like Tkinter.

It’s the literal first example on the GTK website.

In general, GTK is an object oriented library—even in C. You do have to understand inheritance and the object lifetime, from instantiation to finalization, otherwise you are going to have a bad time.

Thank you,

I do see the example you mentioned, however I was referring to the Language Bindings page (gtk dot org/docs/language-bindings). On this page, there is a list and C++ is what is listed, but not C.

What I did not notice until now, is that C++ (not C) is listed for Gtk 3.0 (as well as 4.0).

It would seem to me that (despite my reluctance) I can start converting my app to make use of C++ constructs, while still using Gtk 3.0, prior to porting it over to Gtk 4.0.

Yes, because GTK is written in C and exposes a C API, which means C is not part of the language bindings.

Yes, of course.

For some things, creating GObject/C classes is inevitable: it’s part of the API and of the programming model.

Maybe it was an incorrect assumption on my part, but I was basing it on what I saw on the Language Bindings page (gtk dot org/docs/language-bindings), namely no mention of C, only C++.

I now see that C++ was supported earlier, so maybe I can get my C programming converted over to C++ constructs using Gtk 3.0 first.

Thank you

Thank you, I think I am starting to understand. :wink:

From that page

A binding is like a translation, you generally don’t translate something into the language it’s already in - not sure what that would even mean for Gtk + C

I guess we could generate headers from GIR but it would be rather pointless and just asking for ABI errors (how would renames work? and now you’ve lost all you C utilities APIs that are (skip)ed)

Sure, but if you don’t want to use C++ (and I don’t blame you): Don’t use C++

Just write in C

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.