Why is C/C++ considered low-level languages???


 
Thread Tools Search this Thread
Top Forums Programming Why is C/C++ considered low-level languages???
# 1  
Old 04-11-2012
Why is C/C++ considered low-level languages???

Hi friends,
I hope everyone is doing well and fine. I have always been hearing that C/C++ are relatively low-level as compared to Java/C# etc. Could you please tell me some low-level qualities of C/C++? And I think disk deframenters are written in C/C++, please correct me if I am wrong. And please tell me how I can write a disk deframenter in C/C++, I will really appreciate if you could provide me with some code.

Thanks in advance!
# 2  
Old 04-11-2012
C/C++ are considered high/low level languages because you can write fairly high-level code, with complicated data structures and local variables and functions and various other things you'd find in "high"-level languages, and still have it translated into 100% pure uninterpreted assembly language. You can even write freestanding things like bootloaders and operating systems in C/C++ because you can exercise fine control over what external things are needed -- or, more to the point, aren't needed. You can forgo the standard libraries entirely and write code that depends on absolutely nothing.

This is very different from Java where everything has to be fed through an interpreter all the time. It's not the computer's native tongue, so to speak. You couldn't write a bootloader in it -- you'd need something else to load java first. It's not freestanding, not independent.

Your question unfortunately sounds a bit naive. Writing a disk defragmenter isn't trivial -- you need to understand a lot more than the language, you need to understand the structures of the filesystem in question. If you don't know enough about a filesystem to know which sectors to grab to find out what information, you can't write a defragmenter.

They're often written in C/C++, yes. They don't have to be, but because the structures for these filesystems are C/C++ anyway, it may be easiest to use them rather than reinvent the wheel.

If you want to build a defragmenter for educational reasons, I'd suggest working on the MS-DOS FAT16 filesystem which has very simple organization, then working up from there.

Last edited by Corona688; 04-11-2012 at 02:42 PM..
# 3  
Old 04-11-2012
Thanks for the explaining, it was really helpful. One more ambiquity that I have in my mind regarding the unix system calls like open, creat, write, read etc. The system calls that I have mentioned all all used for file manipulation. We also have functions like fopen, fclose in the same c language for the same purpose. Java, C++/C# also provide classes for file manipulation. Could you please tell me what is the difference between handling files using system calls in c language, and java/C++/C# classes and c functions like fopen etc. Isn't it that the system calls are one of the low-level properties of c language. And is it right to say that Java/C# depend on c language system calls to do their file manipulation jobs, that's why they are considered high-level languages. I will really appreciate your comments. Looking forward!
Thanks in advance!
# 4  
Old 04-12-2012
fopen, fclose, et al are function calls -- they jump your program to a location in memory and execute the code there. If you ran the program in a debugger, you could potentially trace inside these functions and see what they do. They are built for reasons of convenience and portability -- you could build a function which works the same everywhere, for instance, even when the system calls might be slightly different, or add simple functionality like buffers, which is indeed what stdio calls like fwrite are for. It's faster to call putc() 10,000 times to write single chars than to call write() 10,000 times for single chars because putc will just dump it in memory for later.

They certainly can't replace system calls. To write to a file, fwrite() must ultimately call write().

System calls on the other hand are not libraries. They don't jump to the start of an instruction in memory, they pass a message to the operating system, then wait. If you try and trace inside a system call, there's nothing to trace, because your program literally stops running while the system call happens -- the action happens inside the kernel itself, where you can't see.

C is able to freely use raw system calls because it can understand the same data structures the kernel uses for system calls -- the kernel is also C. It compiles it down into raw assembly language like everything else; it becomes the setting of a few registers then something like INT 0x80 to make a software interrupt to inform the kernel you want a system call.

This is difficult for other languages to do natively. Surely they can do INT 0x80, but without the C language itself, it's very difficult to get the data structures right. I've seen some people hardcode system calls in perl and have their code stop working when they move it to a different system, because the data structures changed, but their code didn't. In C, you'd just use the native data structures for wherever you were, and your code wouldn't need to change.
# 5  
Old 05-31-2012
Quote:
Originally Posted by gabam
I have always been hearing that C/C++ are relatively low-level as compared to Java/C# etc. Could you please tell me some low-level qualities of C/C++?
I wouldn't put C and C++ in the same bag.

C is undoubtedly lower level than Java/C# in the sense in can do a lot - but not all - what can do the real low level programming languages which are assembly languages. Also, you can write C code that doesn't depend on a runtime/library, even the standard C library, with C. That's why the vast majority of operating systems kernels are written in C.

C++ is a different story. It is kind of a superset of C however, if you use C++ specific features, you are adding dependencies that make your code much higher level and runtime dependent. That would make for example C++ quite a poor choice for writing a kernel.
Quote:
And I think disk deframenters are written in C/C++, please correct me if I am wrong.
You are probably correct but a disk defragmenter is not that much an example of code requiring a "low level" programming language. You certainly can write a disk defragmenter in Java, or python or whatever.
# 6  
Old 06-14-2012
C/C++ are actually middle level languages, which bridges the gap between high level and low level languages.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

Low level X11 programming

How to use X11 without Xlib not XCB? How draw window directly on low level? I must use anyway window manager like Motif? I have ridden that X11 has server-client architecture, client send via TCP/IP to port 6000 request for primitives and get replies. Where is detailed description of it? In X11... (0 Replies)
Discussion started by: AndrzejB
0 Replies

2. Programming

System calls and C language low-level qualities???

Hi friends, I hope everyone is fine and doing well. I queried in my previous thread about the low-level qualities of C/C++ languages.I really thank you people for explaining, it was really helpful. One more ambiquity that I have in my mind is regarding the unix system calls like open, creat,... (1 Reply)
Discussion started by: gabam
1 Replies

3. AIX

High Runqueue (R) LOW CPU LOW I/O Low Network Low memory usage

Hello All I have a system running AIX 61 shared uncapped partition (with 11 physical processors, 24 Virtual 72GB of Memory) . The output from NMON, vmstat show a high run queue (60+) for continous periods of time intervals, but NO paging, relatively low I/o (6000) , CPU % is 40, Low network.... (9 Replies)
Discussion started by: IL-Malti
9 Replies

4. IP Networking

Best reference for understanding low level info on nic cards drivers and functionality

Hi, What is the best reference that gives in detail on nic cards configuration , assigning multiple ip addresses to a single interface, netlink library etc and all basic stuff at this level..? Thanks (2 Replies)
Discussion started by: Gopi Krishna P
2 Replies

5. Programming

write() issue during a low level hdd access

Hi, I am trying to write zeroes to the hdd using a c program. I don't want to use the dd or ddrescue or any such inbuilt program because of reasons like real time progress, writing custom patterns. (my program is more like an erasure application, but does only zero fill). here are the steps... (35 Replies)
Discussion started by: sponnusa
35 Replies

6. What is on Your Mind?

Programming languages polyglots: how many languages you know?

Post what languages (including scripting) you know, why and where you think that language is most usable. Also include libraries in which you're really good at (libusb, gtk, qt, etc). assembly? C or C++? perl or python? pascal? bash or csh/tcsh? opengl? gtk or qt? mono? (27 Replies)
Discussion started by: redoubtable
27 Replies

7. UNIX for Dummies Questions & Answers

Low level format?

I want to do a low level format like in windows (C:\format c:) but I don't know how it works in unix or linux.. Can somebody help me ? thnx :) (3 Replies)
Discussion started by: day
3 Replies
Login or Register to Ask a Question