DEV Community

Cover image for Is C still a high level language?
Swastik Baranwal
Swastik Baranwal

Posted on

Is C still a high level language?

I keep hearing that C is no longer a High Level Programming Language because it is no abstractions, has pointers, have to handle memory on our own, no string data type, unsafe etc.

Do you think that C is not a high level language anymore? I am against this because it's still readable as any other high level and usable as ever and has many libraries and still been updated.

Top comments (87)

Collapse
 
benwtrent profile image
Benjamin Trent

Depends on from which direction you are looking.

If you are looking from above (Javascript, Java, Python, etc.), it's low level.

If you are looking from below (machine code, assembly, etc.), it's high level.

itDepends

Collapse
 
masonjohnhawver42 profile image
Mason Hawver

So it's mid level or old high level.

Collapse
 
rtosman profile image
rtosman

Levels don't have ages.

Thread Thread
 
v4n5h4j profile image
v4n5h4j

Unless they are normalised.

Collapse
 
adegokekay profile image
Olukayode Adegoke

Ben,

I agree with your point of view - machine code and assembly are definitely lower level than C while Java, Javascript, Perl, and Python are higher level. I will say Pascal is at the same level as C.

-- Olu Adegoke

Collapse
 
benwtrent profile image
Benjamin Trent

I agree, Pascal (and probably Fortran) are on the same level as C.

Collapse
 
gwutama profile image
Galuh Utama

Well, when you have a CPU, the lowest programming language that most of us, mere mortals, can write for the CPU is assembler.

What C compiler does is none other than translating C syntax to assembler. It is still so low that In fact you can insert assembler snippets in C source code. There’s quite a lot of assembler code snippets in Linux kernel C source code.

So yeah, I think it’s pretty low level language because with C you can do almost everything that assembler can do and assembler is the lowest language you can write in.

Collapse
 
alohci profile image
Nicholas Stimpson

Yeah, that takes me back. That's real programming. Not like the namby-pamby memory managed languages I use these days.

Collapse
 
craigmc08 profile image
Craig McIlwrath

Yeah, where have all the real programmers gone?

Thread Thread
 
alohci profile image
Nicholas Stimpson

Thanks very much for that link. A copy of same was posted up in the common-room when I was at Uni, and was in my thoughts when I posted my comment, which was, of course, tongue-very-firmly-in-cheek.

Collapse
 
mindplay profile image
Rasmus Schultz

If this is sarcasm, it's a little too good 😂

Collapse
 
vtgandalf profile image
Valeri Todorov

That it's such a boomer thing to say. Both low and high level programming languages serve their purpose. It's true memory managed languages can be quite slow in execution time and can be resource hungry. On the other hand, you can use C# for example for almost everything and it's suitable for advanced design patterns that are just impossible to implement on C. Unless of course you write your own abstraction level, in which case congrats you just re created C++. Furthermore, C# can be optimized to run almost as fast as C and all executables can be stripped down to run even faster. For Gods sake even python can be optimized to run relatively fast. It all depends on the requirements and the context of the application.

Thread Thread
 
patryktech profile image
Patryk

For Gods sake even python can be optimized to run relatively fast.

And you can always write C modules that you then import into Python.

Collapse
 
pentacular profile image
pentacular

This is really not true at all.

A modern C compiler does quite a lot of interesting work to try to make C code competitive.

Things are reordered and elided and optimized in ways that are often surprising.

Consider what this does in C.

while (1);

If you think it requires the program to loop forever, you are mistaken. :)

Beyond that, there is a great deal that C cannot do which assembly can.

  1. C has no concept of registers (the register storage class just makes a variable unaddressable).

  2. C has no concept of op codes.

  3. C has no concept of the CPUs memory model -- C has a segmented memory model.

C programs run in the C Abstract Machine, and understanding this is essential to writing C programs that do not work only by accident.

Consider the following snippet -- what do you expect it to do in C?

{
  int i = 1;
  printf("%d, %d\n", i++, i);
}
Collapse
 
type1j profile image
Jay Sistar

I agree with you for the most part, but that last paragraph is baseless.

I can insert assembler to Common Lisp and Rust. Both of those out match Python, Javascript, or C++ in abstraction power, so by definition, they are high languages. That doesn't mean that they can't reach down to lower levels of abstraction when they need to do so.

Collapse
 
txai profile image
Txai

Well, I will create another discussion here and ask if this classification "high level" x "low level" languages still does make sense. Maybe when you didn't have another abstraction layers it made sense to classify languages that way, but now i think we should have other classes like "systems language", "scripting language" or something like that. Low level and high level are too widen concepts nowadays

Collapse
 
aggalex profile image
aggelalex

There is no such thing as objectively high-level or low-level. Every language sits uppon a spectrum of abstraction levels. You could even say that CISC assemblies are higher level than RISC assemblies. C is the language that sits just over assemblies and intermediate representations (IRs) and below other compiled languages, like C#, Java, Go, JS, Python, etc. To me, it's supposed to be the language you'd use when another compiled language would create performance issues, but the project is too big to just write it all in assembly.

Collapse
 
theflyingzephyr profile image
Mark West

When you want to work with objects, especially large objects, you often want to avoid moving the objects from one memory location to another as much as possible. This is where C and Cpp dominate, this is on the main reasons why significantly powerful applications can be run on relatively tiny hardware. This is especially true in video and vision applications, where one can, if skilled, map a network input buffer directly to GPU memory, skipping several memory moves altogether that a more abstract approach would require. In addition, highly performant apps often need to explicitly control when memory gets freed in order to avoid getting zapped by a gc getting busy at a random time. In addition, highly performant apps often reuse memory locations repeatedly rather than allocating and deallocating repeatedly. For reasons such as this, C and C++ are for many the highest level of abstraction which apply to the task at hand.

Collapse
 
mxldevs profile image
MxL Devs • Edited

It's relative to what you're comparing to. I'd say it's lower level than some other languages, which is not a bad thing.

Arguably, one can consider most high level languages like Ruby, Python, Java, etc to be not that high level either because you still need to actually write instructions instead of just something more declarative and leaving the implementation up to the language.

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

You might be interested in 3GL and 4GL definitions. However it's somewhat outdated.

Collapse
 
pentacular profile image
pentacular

What does an assembly require?

  1. Access to the CPU registers? C doesn't have this.
  2. Access to the CPU's memory model? C doesn't have this.
  3. Access to the CPU's op codes? C doesn't have this.
  4. A trivial translation to machine code? C doesn't have this.

So, what do you mean by "assembly"?

And how does C qualify as one?

Collapse
 
caiangums profile image
Ilê Caian

I have some thoughts, so here we go:

  • First of all you need to know that concepts like "high-level language" are defined in the CS field. Read this article and consider checking out the CS course from Stanford or at Coursera. Concepts like that does not "change"
  • "It has no abstractions" you are wrong here. It has abstractions for basic types, concepts like Arrays and even syscalls. It also has abstractions for FILEs and a lot of things. If possible, check some basic C course and you will be amazed of how many things C can offer you!
  • "it has no pointers" you are also wrong. C has pointers, and pointers of pointers. They are representations of memory references.
  • "No string datatype": Do you ever wondered why the Strings and Arrays has so many methods in common? They are both almost the same thing: Arrays! 😁 Strings = Arrays of chars!
  • "C is still updated": When Linus was asked about changing from C to C++ the main language from Linux kernel, he answered with a message that C is a Stable language and C++ is continuously "messy" updated (with a lot of not so receptive words...)

C is a language to be used in some specific contexts. As we never should be doing a web-Scrapper using C when we have Python, I think we never will see an OS written in JS.

The answer to your question is: C is a high-level language and this will not change for the CS world too soon.

Collapse
 
delta456 profile image
Swastik Baranwal • Edited

I never said that C has no pointers. I meant C++ std::string.

I keep hearing that C is no longer a High Level Programming Language because it is no abstractions, has pointers, have to handle memory on our own, no string data type, unsafe etc.
Collapse
 
caiangums profile image
Ilê Caian

Actually, the tweet shared by this article said that, as you can see at this link:
twitter.com/ThePracticalDev/status...

About the STD: the C++ Standard Library is a implementation of common useful objects as abstractions. The existence of such thing in C++ doesn't invalidate that C has its own abstractions as I mentioned. I really suggest you to check how C language is constructed and how to implement some basic things such as a basic server with threads, open/read/write files or a basic calculator in C.

I have no intention to offend you but seems like you have no basic notion of how C language works or what is concepts like abstractions and basic data types.

Thread Thread
 
delta456 profile image
Swastik Baranwal • Edited

I get what you mean but people complain that they have to use char chr[] or char* chr for this.

Thread Thread
 
caiangums profile image
Ilê Caian • Edited

There's a big difference between people complaining about something and people being really mindful about knowing the options to it. Compare:

// C
char * str = "hello";
// C++
std::string str = "hello";

There are more letters to be written in C++ and you are including in your executable the full string.h header. Is that valid? Are you really using all of it? For a Desktop application, this makes no sense but for embedded systems, every byte counts.

  • "You can write using namespace std; and...": No. Do not do this in your code. Check this thread at StackOverflow and do some research about it and why is considered a bad practice.

For the 'string' issue, let me suggest another approach:

// C
typedef char * string;

string str = "hello";

As an answer to people who say things like: "C is bad because it doesn't have strings!", consider asking about what they are trying to do. In general, they are complaining about scapegoats.

Thread Thread
 
delta456 profile image
Swastik Baranwal

Definitely! I really agree with you. I hope Dev deletes/changes their tweet.

Collapse
 
aghost7 profile image
Jonathan Boudreau

Technically going by the definition, C could be considered high level. I don't really see how it makes a difference, at the end of the day C nowadays is only employed in niche use cases like embedded systems, kernels, drivers, etc. The reason why it is avoided is because it doesn't have many abstractions, i.e. it is considered too low level for general programming.

Collapse
 
bkahlerventer profile image
Bennie Kahler-Venter • Edited

C was designed as a low-level language with high-level constructs. Brian Kernighan and Dennis Richie needed a language to write Unix in. BCPL, B, and rational fortran - ratfor all contributed to the language now known as C. C is meant to be unsafe and have flexible rules. It was so by design.

It was one of the early universal assembly languages.

 
pentacular profile image
pentacular

Every CPU has a memory model, but other than that you've done a good job of demonstrating why C isn't a portable assembly. :)

Beyond that, if you believe that C has a very strong correspondence to every machine code instruction set, then you believe that every machine code instruction set has a strong correspondence with every other machine code instruction set.

This is simply not true -- let's consider a forth machine.

Or if that's not enough, consider one which runs befunge in hardware.

Now let's consider your example operations.
What do you believe this is required to translate to?

void foo() {
  int i = 0;
  int a[3] = { 1, 2, 3 };
  struct foo { int c; } b;
  b.c = a[i++];
}

When you've done that, let me know what you think this does:

void bar() {
  while (1);
}

And then let's finish up with a more interesting example.
What does calling this do?

void quux() {
  int i = 1;
  printf("%d, %d\n", i++, i);
}
Collapse
 
vonheikemen profile image
Heiker

Depends on who you ask. Some people who only know languages like ruby or javascript could look at some C code and maybe think "I can do all of that in one line of [prefered language]". Maybe that's the reason why they think C is no longer high level.

Collapse
 
tomas2387 profile image
Tomás Prado Bley

Everyone should knew this was going to happen as every 5 years we see new languages include in their main features: "ease of use", "garbage collected", "transparent to dev memory allocation".
As a result, C is pushed out from the "high level lang." definition every time a language is born in popularity with those characteristics, and that's because today is so far away from those new "high level languages" we cannot consider it a high level lang anymore.

Collapse
 
guitarino profile image
Kirill Shestakov • Edited

I think the term high-level language was only created to contrast them to low-level languages.

Low-level languages are languages that can be used for both low- and high-level programming.

High-level languages can only be used for high-level programming.

Think of writing a driver. You can probably only write it in low-level language. However, it doesn't mean high-level programs can't be written in it. So, C can be used for both, even though it's not a high-level language. That's only my take on this, I'm not an authority on this.