Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Short answer: Yes</p> <p>Long answer: Yes, but you probably won't gain much because you will end up duplicating most of the work yourself.</p> <p>Header files, like stdio.h, usually provide lots of function <em>declarations</em>. Note that declarations are not <em>definitions</em>. Declarations merely tell the compiler to trust that the function exists (and allow you to call it), while definitions provide the code for the function itself. </p> <p>You are providing a declaration for scanf(), so the compiler allows you to call it. However, the stdio.h header already provides a declaration for scanf, so you don't really gain a whole lot. Furthermore, the only reason that this <em>just works</em> is because the definition for scanf() happens to already exist in your executable --- most likely because it is a library function and your compiler automatically includes that library. If it had not included the library that contains scanf(), the linker (which runs after the compiler) would have complained and given you an error along the lines of "undefined reference to scanf()...".</p> <p>So, you can avoid using the standard headers by providing declarations for all of the library functions you wish to use, but you must be careful that the declarations you provide match up exactly with what is contained in the library (else you may get unresolved symbol/reference errors from the linker). This is in fact the job of most headers --- they act as 'contracts' between different modules of code. In this case, the stdio.h header is a 'contract' for some of the functions provided by the standard libraries: it allows you to call them by providing declarations, but furthermore, it implicitly claims that the definitions for those functions exist somewhere.</p> <p>With all that in mind, do you really want to avoid including the headers and having to manually pick and choose which functions you declare (while simultaneously cross-checking to make sure you got the declaration right)?</p> <p><strong>Edit</strong>: I may have misunderstood the purpose of the question. Yes, you should be able to write nearly any program and use nearly all APIs without actually including a header, but you will have to tediously cross-check all of your declarations to make sure that they are correct. You will also lose out on any inline definitions provided by headers for optimization.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload