Warning: This query also contains specifics about MSVC compiler.(If you find it important to change the tags feel free to do so)
I used vscode(dev cmd-invoked) integrated terminal to compile.
cl {filename} to compile and
{filename} to run
Question
As once I was wondering how printf works. So, I sat down and tracked down the code for printf and shortened it as much as possible.
But now I hit a dead-end. there are so many functions and macros I had no idea existed. But that's not the problem I'm stating here. The problem is: I came across some function that I never found its source code in any of the header files. (I've came across files like these before but always ignored, but now its time that I learn about it..)
int main()
{
// printf("Printf base code search\n");
char* _ArgList;
char* _Format = "Hello Printf!!";
_ArgList = (char*)&(_Format) + ((sizeof(_Format) + sizeof(int) - 1) & ~(sizeof(int) - 1));
_vfprintf_l(__acrt_iob_func(1), _Format, (void*) 0, _ArgList);
}
I have extracted the macros from multiple files(~ >5) and put it in the required place to minimize code lines. Now I can print any string with this code. There are two functions at the last line:
- _vfprintf_l()
I learnt that it is responsible for the actual printing of text. - __acrt_iob_func(1)
I later found out from stack overflow itself that it's not a function but 'stdout'(I don't have details)
But I couldn't find any details about it on any header files or internet.
So, I'll appreciate if I get some information about these
Q1. _vfprintf_l(). How is it declared and where? Why can't I find it's source code. Is it because it's inside a dll file? If yes, then which one? I learnt as much as I can from here (microsoft docs about it)
Q2. __acrt_iob_func(1). How is it defined and where?..
Q3. Where are all the built-in types like int, char are defined in MSVC. I read the documentation from here (MS docs)
and here, here (stackoverflow links)
Where are these types defined. Is it defined using C or is it defined using Assembly language?..
Q4. Since I haven't included ANY header files but how does the C built-in data types and the built-in functions like(sizeof() and _vf_printf_l() are getting linked. (other compiler users can also share how it happens on there too).
This question is most recent among these.
Q5. in stackoverflow this answer says that most cpu's support these data types directly. Does that mean built-in data types are programmed in machine language all the time or we can get by using a high-level language(doesn't seem likely)? If I were to build a new data type(so basic that I can't use the fundamental data types defined in c to build it) Will I need to use assembly instructions to build that data type. If I were successful in creating the above data type then, How would I link it with the program as an external data type. How can I link it as a built-in data type(so that I don't have to include or link any file for that
Let me tell you I have done my homework on it for 2 days with 0 or low clarity. Even after that if you think I need to read a info source, I will still appreciate, but please keep that in mind
I'm in no hurry. Please answer as much as you can.
Update:
All these questions can be summarized/answered into/from one question.
-> How and where the built-in data types are defined. so that it is able to successfully link to a code without linking another file(like int) and how can a programmer add his own BUILT-IN data-type.
<--The End-->
(I know It's not necessary, I'm asking if any way I can start learning about these, If it is a separate topic altogether then knowing the name of it would be even helpful.)