But in principle, can one construct flashy functions built out of only the standard C libraries, and then by using only those functions, make it portable? Or is the only way to make flashy functions is to use OS-specific functions provided by the OS-manufacturers?
I vaguely recall that in C...
I'm slightly confused here. If your program only uses standard libraries, then it ought to be portable right? The pre-processor will look for <stdio.h> wherever your operating system stores it under its file management, find it and then paste it into your program. It is not the programmer's...
Is fcntl.h more fundamental than stdio.h?
Using just stdio.h, I can define a FILE type, and use an fopen() command to open a file and return the address of the file into the FILE variable.
Using fcntl.h, I use open() instead of fopen(), and instead of returning a FILE type, open() returns...
That's what puzzles me. I understand for dynamic linking there will be something else besides machine code. But if you statically link a program, then I thought it would be all machine code.
I thought the only thing that differed from OS to OS was memory management. So the reason that a...
I always wondered why do you separate the memory of a program into different segments, such as code space, data space, and stack space. Why does code have to be by code, and data be by data, etc?
I read that DOS does not separate a program into segments.
I was reading some information on...
Would it be correct to say that C prevents you from writing self-modifying code by preventing you access to the addresses where code is stored, and that is the primary reason that not initializing pointers is dangerous? And why can't the language automatically set each pointer to NULL? Is this...
I think it's worthwhile to learn more about computers, even if you aren't going to do anything with computers professionally, since computers are everywhere.
You know how to post in a message board, use e-mail (to get an account on the message board), and can probably surf the net (to find...
Thanks everyone. I tried googling examples of strings and C, but none of the examples I found provided your level of knowledge.
I understand it now.
I'll stay away from the string table, and just use:
so that I can have strings stored in the normal data space...
Are you allowed to overwrite the string table?
Because this program produces a segmentation fault:
ptr="this is a test";
If the line ptr="this is a test";
inserts the address of the string table where "this is a test" begins into ptr, then from what you...
I searched all over for the header files on my linux system, and all I could find are C header files in /usr/include/, and they all have .h extensions. Actually, I don't believe my distro came with g++ installed, so maybe that's why I can't find iostream or iostream.h
Maybe I'm not...
I was playing around with C to try to discover how it assigns memory, so I wrote this:
printf("address of dynamic memory: %p", ptr);
printf("address of a pointer: %p", &ptr);
printf("address of an integer: %p", &test1)...
Thanks, that was very helpful.
I noticed that if I typed in:
whereas if ptr were a char pointer, the addresses would differ by only one byte instead of four.
Actually, something weird is going on. If I type this code:
printf("enter a sentence");
printf("you entered: %s", ptr);
then the compiler doesn't complain, but I get a segmentation fault. However, if I put in a 25 before the %s like this...
If I declare an array like this:
then there is automatically a pointer that I can use called array:
which is equal to
I didn't ask for the pointer, but somehow C has it built in that the name of an array acts as a...
In C, why do you have to define a pointer type? For a 32 bit computer, the address is 4 bytes long no matter what, so it shouldn't matter if the pointer is to a char or an int, yet I get a compiler warning when I use a char pointer to point to the address of an int.
Also, I don't quite...
What is the difference between ANSI C, ISO C, and POSIX?
I know that they refer to some type of standards, with ANSI being American and ISO being international, and that POSIX refers specifically to Unix-like OS's, which I assume means things like Linux and Mac (but what about UNIX: does...
So somewhere in libc.a is a definition of the standard data types like int and double?
Because in the programming snippets for beginners that I've seen, it seems like they don't have to #include libc.a. , and the linker doesn't complain when they have:
All they include is stdio.h...
I was looking at unistd.h , which seems to be a runtime system call library for C, written by unix manufacturers and not the makers of C compilers. Even if you allocate all the memory at once (as you say you make just one system call to allocate the memory), don't you still need a C header like...
I'm nowhere near knowledgeable enough to write my own language! I formulated a hypothetical to try to better understand the relationship between OSs and libraries more.
When you declare a variable in C, doesn't that require a system library, since the OS needs to make the space for that...
Is it true that the the makers of the programming language C get to specify standards for runtime libraries, and operating manufacturers must implement those standards in the runtime libraries they provide for C?
Or do the operating system manufacturers tell the makers of C "here are my system...
Would it be correct to say that a compiler is processor-specific, but a linker is what really
has an operating system dependence?
I thought a compiler only makes 0s and 1s, but I read that although the .o files have the 0s and 1s, the memory addresses associated with variables are still...
Thanks to everyone for explaining things to me. I know what I say makes little sense, so that it's hard to figure out where I'm going wrong and respond.
I have some more questions:
As far as I can tell, system calls are libraries in C. So if you are writing a program in say Fortran, would you...
I think I have a fundamental misunderstanding of what a compiler is. I thought it converted your high-level language into 1s and 0s for your particular processor, and the job of the operating system is to just load the program into CPU memory. But evidently this is not the case. Instead a...
I understand that you can write a complete operating system in a high-level language like C++, compile it into machine code, and then write it to storage, and then sell it or give it away.
But is this historically what was done? Did the compiler come first, or the operating system?
I sometimes see compilers advertised as written for 32-bit Windows. Are they assuming the x86-32 architecture? I was thinking that it could be the case that 32-bit Windows was only written for the x86-32 architecture, so when you specify 32-bit Windows you automatically specify x86-32, but I...
A compiler converts a high-level language to machine code. So when you buy or download a compiler, don't you have to make sure the compiler is compatible with your microprocessor? Yet when I look at the various compilers I can download, the requirements are listed as what operating system you...