Computing.Net > Forums > Programming > How powerful is C?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How powerful is C?

Reply to Message Icon

Name: saddam (by lurker)
Date: December 3, 2004 at 19:55:08 Pacific
OS: Windows XP
Comment:

Hello,

I have heard wounderful things about C like the ability to control machines which cant be done in higher level languages directly.

However, I am getting to be skeptical about this because currently all the programs I created in C are command-line ones and write files.

Could someone point me in the right direction of how this is achieved?

Any resources are generously appreciated.

saddam



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: December 3, 2004 at 20:24:00 Pacific
Reply:

Which version of C are you using? Sound to me like you are using a DOS version in which case a command line programmes is all you will get.

You need to be using a version of C++ designed for Windows. C++ is a powerful as you want to make it when you consider that Windows itself is written in C++.

Stuart


0

Response Number 2
Name: Sord
Date: December 3, 2004 at 21:28:28 Pacific
Reply:

Stuart,
He said C, not C++. They are not the same. C++ can create console (command-line) programs and C can create programs with a GUI.
And there is no "DOS version" of C. It is simply a specification for a language. There are DOS compilers, but a linux compiler, DOS compiler, and Windows compilers can all create console programs.

saddam,
C is a high level language, assembler is not. (And yes, assembler can make GUI programs too, even Windows based ones) The reason it can have more control over the hardware is because it can be linked with assembler objects and can contain inline assembler. C++ can do the same.

C is pretty much the most powerful you will get without using assembler. The majority of the linux kernel, FreeBSD kernel, probably Windows kernel, and just about any operating system kernel is in C (with assembler where needed).
C++ is an extension of C which can be just as powerful and be used for the same tasks (after writing a few extra things to allow things such as new and delete to work when it comes to OS dev).


0

Response Number 3
Name: StuartS
Date: December 3, 2004 at 22:10:05 Pacific
Reply:

>> He said C, not C++. <<

I know he said C thats why I suggested he use C++ and made me think he was using a DOS Compiler if you want to be pedantic.

C++ is a lot more powerful than plain C as it is Object Orientated which plain C isn't. Makes life a lot easier for the programmer.

Although it is possible to create a GUI in DOS, it's a hell of a lot of work. The programmer would have to write his own graphics library for every graphics device the programme would run on. No device drivers in DOS and with no Objects to play around with it is hard. A lot easier with C++ inside Windows where most of the dirty work is already done for you via the Windows API. As I said earlier, Windows is written in C++, not C.

C is a high level language. But compared with something like Visual BASIC, it is a low level language. Not as low as assembler which the original poster never mentioned.

Stuart


0

Response Number 4
Name: Sord
Date: December 3, 2004 at 22:25:43 Pacific
Reply:

Easier != More Powerful

And by C and GUIs I did not refer to a DOS GUI. C can access the Windows API just as easily as C++ it just cannot do so via classes.

Also, the Windows API is in C++, but not Windows itself (as far as the kernel goes).

My appologies for being so harsh on my previous post, its been a bad day.


0

Response Number 5
Name: saddam (by lurker)
Date: December 4, 2004 at 01:43:59 Pacific
Reply:

Hi,

Thanks for the answers.

sord:

"The reason it can have more control over the hardware is because it can be linked with assembler objects and can contain inline assembler."

Can you or someone show me an example C program that does that?

The type of hardware I am refering to are stuff like motors and engines, data acquisition in C.

"My appologies for being so harsh on my previous post, its been a bad day."

No offence, I understand many people on this forum are sometimes busy and have bad days, I know.


0

Related Posts

See More



Response Number 6
Name: Sord
Date: December 4, 2004 at 19:09:03 Pacific
Reply:

saddam,
As far as control over motors and such, you would need a way to connect it to your computer and then know how to control the hardware. For that I have no example, I was refering to the computer's hardware (such as floppy controller, APIC, etc)

And as far as having a bad day, I was talkign to Stuart


0

Response Number 7
Name: wizard-fred
Date: December 4, 2004 at 22:53:42 Pacific
Reply:

Although C can be used for industrial controls, it may not be necesssary If you application is relatively simple, you can use programmable microcontrollers like Microchip's PIC or Atmel's AVR. Many of the these chips are programmed in BASIC. These chips are frequently used because they have many channels of digital IO, builtin ADC and DAC, and timers. Frequently there is enough RAM and EPROM on the chip so you don't need external memory or program storage.

So what control applications do you want to do?


0

Response Number 8
Name: tommycoolman
Date: December 4, 2004 at 23:22:08 Pacific
Reply:

The Windows API is in C++? It looks all C to me. I haven't seen any C++ classes in the Win32 library or anything else that would suggest it's C++.

MFC, that's a different story.


0

Response Number 9
Name: Wolfbone
Date: December 5, 2004 at 02:16:43 Pacific
Reply:

I know that at least for some of the kind of hardware you mention, attached to the standard interfaces on a PC, language hardly matters much. You can write such programs in Java, MatLab and even Perl. Inline assembly isn't unique to C either is it? and any compiler that compiles any language into assembly code will presumably offer it as a facility - it's not really anything to do with the language itself. It fits quite naturally in C source probably because C is a relatively thin layer on top of assembly anyway. Also, if you're programming in C, you may well be doing so precisely because you need the low level machine efficiency of it in the first place. C was designed iirc for making writing OSs easier than in assembly alone, which is probably why using inline assembly is so closely associated with it and it's compilers. If you've chosen C for a project, you're much more likely to need to go even further by using inline assembly (maybe for machine specific stuff or optimization) if not actually writing the assembly source for whole objects. Your C compiler should have good documentation about using it (gcc does) and the source trees of projects like OSs, video codec libraries and video players should be full of examples of it.

So returning to the question of what's so wonderful about C (assuming your original question was meant more generally than about just hardware control), then one of the main advantages of it (and maybe C++) that I have found is the sheer speed of the code you can end up with. It is certainly my experience of mathematical libraries and programs - the GMP library for example (written in C and probably some assembly too) is afaik the fastest there is for arbitrary integer calculation. But C is not just good for complex and explicitly mathematical stuff: there was a problem a while back in this forum about finding the relative complements between pairs of files full of text records - as quickly as possible. I found that the times taken for three roughly equivalent programs in Awk (not compilable of course), Common Lisp and C were 38m, 4m33s and 50s respectively. In C it was easy to attack this - memory access and byte comparison - problem directly, with pointer manipulation and the assistance of mmap from the OS. I didn't try C++ (such a small program probably wouldn't have looked any different to the compiler than the C one) but I believe it's much harder to write optimizing compilers for more complex languages. Not only that but I find that if I write a C program and want to tune it myself with the compiler optimization flags, it is just about possible for me to understand what they mean and what effect they will have on the program. If it's C++ I have absolutely no idea of what flags to use or what the outcome will be ;-)

As an aside there is an interesting tool (well - language really) called Lush that provides an analogy for the use of inline assembly in C programs. It was developed as a Lisp dialect specifically for doing large scale AI stuff like machine learning, handwriting recognition, scientific visualization and other heavily mathematical work. Lisp is the ideal language for this kind of stuff but it is often desirable to have highly optimized code in parts of those kinds of project. Lush meets that requirement by allowing you to write inline C code (not just interfacing with external C libraries) - just like a C programmer might use inline assembly.

Sorry to go on at such length but the intermingling of different languages, accessing of alien libraries and matters of balancing optimization and productivity are especially interesting to me at the moment :)


0

Response Number 10
Name: Robert Hedan
Date: January 3, 2005 at 12:22:52 Pacific
Reply:

"Easier != More Powerful"

I think that's about as far from the truth as you can get.

Assembler is the most powerful language, it can do anything, access any bit of memory. As for it being 'easier' than other languages, sorry, the only thing harder than Assembler is reading a HEX dump directly.

The higher level the language, the easier it is. Look at COBOL; MOVE a TO b. You can't get much easier than COBOL, or BASIC. But they cannot do everything Assembler can do.

Assembler is about as close as you are going to get to thinking like a computer. All the other languages we designed to help humans understand them and write easier.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How powerful is C?

What is C++? www.computing.net/answers/programming/what-is-c/10480.html

help me in c www.computing.net/answers/programming/help-me-in-c/8581.html

How bad is it... www.computing.net/answers/programming/how-bad-is-it/12825.html