Using header files in C -


i'm trying learn use of header files in c. found few resources in research none of them created desired effect.

first, according this tutorial, can write functions in header file itself. don't want that. want keep header file unchanged if changed code given interface remains unchanged.

answer this question suggests 2 methods. first can write code , header file separately , include them when compile follows:

gcc -o myprog test.c library.c 

but don't want either. library functions should readily available without needing include in compile line. according same answer, create library , link -l switch. when comes functions printf, don't need either of them. have include header files.is there way of doing that?

summary tl;dr

i want write library in c which:

  1. doesn't have implemented in header file itself.

  2. doesn't have included in compile line every time use library functions.

  3. doesn't have linked -l every time use library function.

  4. basically library should used including header file.

is there anyway in linux?

but when comes functions printf, don't need either of them. have include header files.is there way of doing that?

short answer "no". long answer c compiler links libraries "for free", including library implements printf.

you have option decline these "freebies" - in gcc it's -nodefaultlibs. if add option, printf missing.

note: 1 thing headers can implement macros. however, macros not behave normal functions, should approach them great caution.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -