Question:
Do we have to know DOS commands and Win32/64 programming to create 'System Call' functions in C programming language?
ioio
2014-12-27 15:40:12 UTC
It's like calling the system () function in a C function to pass an string (i.e. A DOS command) to the environment for execution, right? i.e."C:\\Users\\Leon\\Desktop\\File.txt"

You know, i'm interested in sys/types.h and sys/socket.h libraries. I can only code in C, and haven't yet created any big program - i mean, i am on it, but i limited myself to C Standard Library - i've made many functions and small programs in it, but they're all under DOS. You know i love GUI, but i really want to create it 'Myself', not just, you know, 'Using' others' works.

But C Standard Library says nothing about Networking and GUI. I thought we have to create separate libraries ourselves, but i don't even know where to start to create GUI or Networking stuff! I can't even imagine how they created some API's in C language. i.e. Win32/64 API.

I am still learning C and am not yet ready to say "I know C completely" - No - but i don't think the keyword 'struct' can do it all!

I heard that Microsoft created Win32\64 API in C language. Is that true? Wikipedia says No.

Please help me with this: I can't leave C, i love it, i can't go to C++ or Java or C# or any other OOP, i just can't, i hate 'Information Hiding' thing. I even have my own versions of functions that are part of C standard library like memset, strcat, strcpy. All i want, is to 'Know' what i'm writing. So, yes, i love to write them from scratch, because it makes feel proud of myself. I can only think of Procedural paradigm.
Three answers:
amania_r
2014-12-27 16:16:17 UTC
System calls and the system() call are completely different things. System calls are any function calls that call operating system features. Brk(), exec(), getcwd(), read() are examples. You can write anything in C, no need to switch languages.
?
2014-12-27 21:31:33 UTC
You sound to me like you are learning from terrible resources.

Almost everything you've said reeks of misinformation.



If you have a modern Windows computer, you are not running DOS. DOS does not exist on your system. The "command prompt" program which runs on your computer is a shell. You can run programs in it and perform some other rudimentary tasks as expected. It's actually terribly inadequate, but it's Windows.



Let me explain explain the standard POSIX `system ()' function:

This is NOT a "system call". I see why you might think that, but system () is a POSIX and standard C function.

It is equivalent (on standard systems) to running the default shell (named `sh'), with the flag "-c", and command as the c-string passed to it. (It executes it's argument in the shell). But Windows is a special child.



On Windows, it spawns a new process, directly equivalent to issuing

cmd.exe /c [arg1]

On a standard system, the difference appears mostly cosmetic:

sh -c arg1



This technique is generally called "shelling out". It's sometimes useful because it reduces functional duplication, complexity, hides information, and is otherwise generally good practice, if you can get away with it. Under Windows, it's more slow and dangerous than usual. Other than the value returned from the shell, there is no way to receive information from the program retrieved.



So that's system().



A system call is totally different. It's the bridge between the kernel and your program. Your implementation of the C standard library, the Win32 API, etc. make calls to these functions as provided by the kernel. You cannot implement them yourself. Examples include _sopen_s (), _wopen () _telli64 (), etc.



Here is the documentation for _sopen_s ().

http://msdn.microsoft.com/en-us/library/w64k0ytk.aspx



Most programs would never need to invoke those calls directly. They are backward, error-prone, non-standard, terribly complicated, and offer no benefits in most cases.



"But C Standard Library says nothing about Networking and GUI. I thought we have to create separate libraries ourselves, but i don't even know where to start to create GUI or Networking stuff!"



No, it doesn't. C is a systems programming language, for one.

You're a fool if you try to create those libraries yourself! (and expect to get anything done)

If you're using C, you would start by invoking the WinAPI, for GUI, or Winsock (a twisted, nonstandard implementation of BSD Sockets) for networking.



Listen:

I could continue, but you're looking to write everything down to the circuitry. While _fun_, you need to decide what your goals are, focus on learning the language, and then re-approach learning how exactly GUI shows up on the screen.



The last paragraph of your (series of) question(s) is an absolute engineering travesty. There is a humongous disconnect between the skill implied by that paragraph and the skill required to do what you are implying.



Information hiding is the only sane way to accomplish anything. Taking what you have said to the extreme, you should not be writing C, you should be hacking Assembly, or rather running a hex editor, entering bytes of machine code from the processor datasheet next to you.



I strongly suggest reading some of these. I stripped out many of them not directly applicable. They are all good.

1. ) Robert C. Martin -- Clean Code: A Handbook of Agile Software Craftsmanship

2. ) The GOF (Erich Gamma et al) -- Design Patterns: Elements of Reusable Object-Oriented Software

3. ) Steve McConnel -- Code Complete: A Practical Handbook of Software Construction, Second Edition

5. ) Frederick Brooks -- The Mythical Man-Month: Essays on Software Engineering

9. ) Eric S. Raymond -- The Art of Unix Programming

13. ) Thomas & Hunt -- The Pragmatic Programmer

18. ) Donald Knuth -- The Art of Computer Programming (a reference: which I don't own, I get the library's copy)



Hacking around in the bits is fun... building your own OS is fun... But it's _hard_! Learn first!

If you want, send me a message via YA.
?
2014-12-27 21:39:47 UTC
That was a different thing. Better programming in Unix OS, it's a open-source software


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...