Search results

  1. R

    System library versus standard library

    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...
  2. R

    System library versus standard library

    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...
  3. R

    System library versus standard library

    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...
  4. R

    Memory addresses

    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...
  5. R

    Memory addresses

    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...
  6. R

    Pointers and strings

    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...
  7. R

    Guidance & Advice

    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...
  8. R

    Pointers and strings

    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: char string[100]="..."; so that I can have strings stored in the normal data space...
  9. R

    Pointers and strings

    Are you allowed to overwrite the string table? Because this program produces a segmentation fault: main(){ char* ptr; ptr="this is a test"; scanf("%s",ptr); } 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...
  10. R

    C/++/# Multiplication issue in C++

    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...
  11. R

    C/++/# Multiplication issue in C++

    Which entities would you have to add by hand if you didn't tell the compiler that? Also which block? main()?
  12. R

    C/++/# Multiplication issue in C++

    What does the line: using namespace std; do? Is std the name of a variable, namespace the type, and using a descriptor for the type? As in long int number; ?
  13. R

    Memory addresses

    I was playing around with C to try to discover how it assigns memory, so I wrote this: int test1; int test2; char test3; int* ptr=malloc(3*sizeof(int)); printf("address of dynamic memory: %p", ptr); printf("address of a pointer: %p", &ptr); printf("address of an integer: %p", &test1)...
  14. R

    Pointers and strings

    Thanks, that was very helpful. I noticed that if I typed in: main(){ int* ptr; printf("%p",&ptr[0]); printf("%p",&ptr[1]); printf("%p",&ptr[2]); } it gives: 0x42aff4 0x42aff8 0x42affc whereas if ptr were a char pointer, the addresses would differ by only one byte instead of four. So...
  15. R

    Pointers and strings

    Actually, something weird is going on. If I type this code: main(){ char* ptr; printf("enter a sentence"); scanf("%s", ptr); 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...
  16. R

    Pointers and strings

    If I declare an array like this: char array[]="testing"; then there is automatically a pointer that I can use called array: printf("%p", array); which is equal to printf("%p", &array[0]); I didn't ask for the pointer, but somehow C has it built in that the name of an array acts as a...
  17. R

    Pointers and strings

    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...
  18. R

    C Standards

    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...
  19. R

    Runtime libraries

    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: int x=1; All they include is stdio.h...
  20. R

    Runtime libraries

    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...
  21. R

    Runtime libraries

    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...
  22. R

    Runtime libraries

    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...
  23. R

    Operating system and programming language

    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...
  24. R

    Operating system and programming language

    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...
  25. R

    Operating system and programming language

    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...
  26. R

    Operating system and programming language

    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? When you...
  27. R

    Newbie question on compilers

    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...
  28. R

    Newbie question on compilers

    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...
Top