In C, almost everything requires a function. What nags me is that I don't know exactly what's going on. If there was no msvcrt.dll
file, my C programs would all break because that's where all the standard library functions are. I would like to know what the equivalents to the standard library functions are, but without having to import stdio.h
or stdlib.h
. Is there a list of things you can do without the standard library's assistance? I would like to reach "pure" C without pre-defined functions.
-
2Remove section 7 from the C standard and you've got your list.– BlrflMar 21, 2017 at 21:18
-
2You might enjoy working through the Bare Bones tutorial on osdev.org .– 5gon12ederMar 22, 2017 at 0:56
4 Answers
Is there a list of things you can do without the standard library's assistance? I would like to reach "pure" C without pre-defined functions.
Think about the things you can do in C. Then remove the things that require pre-defined functions. That's what's left.
You could write your own strcpy
or memset
or sprintf
, but there's no way to write printf
in C without calling a pre-defined function. On Linux printf
will eventually call write
which is written in assembly; on Windows it will eventually call WriteFile
from kernel32.dll which calls internal Windows functions that change between different versions of Windows.
A good chunk of the standard library is there to provide a portable interface to system-level functions, such as I/O, dynamic memory management, process management, time and date functions, etc. Without it, you'd have to replicate all the low-level system calls yourself, at least some of which will have to be written in assembler (i.e., not "pure" C).
On a hosted implementation (basically, anything with an operating system), the whole standard library should always be available to you. On a freestanding implementation, only a small subset of the standard library may be available, but on such an implementation you won't be doing anything that would require those functions anyway.
I didn't really understood what you willing to achieve.
You want to write c module where you don't want to use any standard library functions in it?
Example: The stdio.h header defines three variable types, several macros, and various functions for performing input and output. In order to use fopen in your module you need to include the header file "stdio.h"
FILE *fopen(const char *filename, const char *mode)
Opens the filename pointed to by filename using the given mode.
If you don't want to use fopen then you need to write your own implementation of file open but that is reinventing the wheel.
If you intend to ask, you want to have own isalpha() or isnum() kind of functions to implement, you can write that on your own header, include that in your c source file.
Dynamic linking of DLL:
You can import dll, that is dynamic libraries, link those libs and use that function in your module. Even in that case you need to include the necessary header files.
Mentioning msvcrt.dll sounds to me like your real concern is proprietary windows-specific functions that might not be universally (or "eternally") available, thus breaking your applications if they (msvcrt.dll, etc, https://en.wikipedia.org/wiki/Microsoft_Windows_library_files ) are dependencies. I think you might be happy/content using Posix standard library functions, see, e.g., https://stackoverflow.com/questions/9376837/difference-between-c-standard-library-and-c-posix-library or https://en.wikipedia.org/wiki/C_POSIX_library for which the source code is freely available, e.g., https://www.gnu.org/software/libc/
So maybe what you want to do is determine which windows standard library functions are identical to posix counterparts, and restrict your application code to that subset. It's kind of impossible to do anything non-trivial without using any standard library stuff whatsoever.