Home > Article > System Tutorial > Five ways to learn C on Linux
There are many different views on the reasons why the C language has been able to flourish for so long. Some people think it is because its syntax is concise and clear, others think it is because it is considered a practical language that can be compiled and run on any platform without relying on other high-level languages. C is undoubtedly a powerful language, and I think its longevity is inseparable from the way it serves as the foundation for other technologies. Here are 5 of my favorite C-based techniques that I hope will help you learn more about C.
C language is not an object-oriented programming language. It does not have the class
keyword. Some people do object-oriented programming in C, but others stick with C and the GObject library. The GObject library provides a class
structure for the C language, and the GTK project is known for providing toolkits accessible through C. Without GTK, there would be no GIMP (for which GTK was developed), GNOME, and hundreds of other popular open source applications.
learn more
GObject and GTK are great ways to get started with GUI programming in C. They are "well-equipped" to let you program graphics applications in C because the developers do a lot of the "heavy lifting" for you. They define the classes and data types, create the toolkit, and all you have to do is put everything together.
If GTK exceeds your needs, you may decide that a terminal user interface (TUI) is more suitable for you. The Ncurses library can create "widgets" in the terminal, creating an application that draws graphics on the terminal window. You can use the arrow keys to control the interface and select buttons and elements, just like using a GUI application without a mouse.
learn more
Use the Ncurses library to write a guessing number opensource.com game in C language.
Lua is a scripting language that can access C language libraries using the built-in C API. It's very compact, fast, and simple, with about 30 functions and a handful of built-in libraries. You can use Lua for system automation, game modification and scripting, a front-end like LÖVE for game development, or GTK for general application development (e.g. Howl Text Editor🔗 opensource.com).
The great thing about Lua is that you can start learning and mastering basic programming concepts from it, and then explore its C language API when you are brave enough to face the basic programming language. On the other hand, if you only know Lua, that's fine. Lua has many external libraries - opensource.com , making it an excellent choice for a variety of development styles.
Lua is not the only programming language with a C interface. Cython cython.org is a compiler and programming language designed to make writing C extensions for Python as easy as writing Python code. Essentially, you can write Python and end up with a C program. The simplest example:
print("hello world")
Create a setup.py
script:
from setuptools import setupfrom Cython.Build import cythonizesetup( ext_modules = cythonize("hello.pyx"))
Run the setup
script:
$ python3 ./setup.py
Finally you will get a hello.c
and hello.cpython-39-x86_64-linux-gnu.so
files in the same directory.
Cython🔗 opensource.com is a superset of Python that supports C language functions and data types. It's unlikely to help you learn C directly, but it opens up new possibilities for Python developers who want to learn C code and integrate it into Python.
The best way to learn more about the C language is to write C code, and there's nothing more exciting than writing code you can actually use. The FreeDOS project is an open source implementation of DOS, the predecessor of Windows. Maybe you've used FreeDOS, either as a convenient open source way to run BIOS updaters, or to play classic computer games in an emulator. You can do more with FreeDOS. It's an ideal platform for learning C, with a range of tools that encourage you to write your own commands and simple (or not so simple, if you prefer) applications. Of course you can write C code on any system, but the convenience of FreeDOS may be refreshing. The sky is the limit, but even on the ground you can do some really interesting things with C.
The above is the detailed content of Five ways to learn C on Linux. For more information, please follow other related articles on the PHP Chinese website!