.h is header file, human readable, pre-processor logic, definitions.
.o is object file, not human readable, binary format, linker can "concatenate" these and a binary header to get an EXE.
.a is a library, binary format, statically linked, has everything it needs inside itself, an EXE can call functions inside directly.
.so same as .a but dynamically linked, it imports functions from other .so, other .so can import functions inside, an EXE can call functions inside directly.
.dll same as .so but for Windows.
.dynlib same as .so but for Mac.
I dont code C directly, but I use Nim that compiles to optimized C/C++.
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
10 plus years* active enterprise development experience and a Fine art degree 🎨
Nice and simple thanks Jaun. I can tell your enjoying Nim so I won't probe to much. But I still wonder how I can write a program in c that consists of several, from what you say. .c files. I guess .h files are just for macros and those define statements etc. Not for:
intadd(inta,intb){returna+b;}
Maybe I can include .c files into the main .c file?
These are used during compilation, where multiple files A.c, B.c, C.c depend on some given function(s) in file D.c. The files A.c, B.c, C.c can be compiled using the information in the header file D.h only, which contains the function name and signature. The real code in D.c that has the logic you want to run is associated later, during linking.
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
10 plus years* active enterprise development experience and a Fine art degree 🎨
Be careful though, according to the video, you declare a function prototype in the header is clearer, otherwise people like myself would had wrote a real function in the header with logic (which I have done 😳).
Well, there are two terms here which are distinct - declaration, as Nested said, is giving a prototype of a function or a name of a variable.
void f()
Defining is giving the function it's body (the code of the function).
void f() { return; }
The declaration tells the compiler what to expect and a promise that we will give him that exact thing at some point later.
We can use this to our advatange - for instance by declaring all the functions at the top of the file and then defining them bellow, which helps us better organize the file for human reading.
Similarilay, you put the declarations in the header, and the definitions in the .c file.
You can also both declare and define the functions in the header file - these are called header only libraries (many cool ones available online). The problem with this is that if you have A.c, B.c, C.c, all of them will copy-paste all the functions from the h file into the end result, which can cause slower compilation and potential conflicts. This can by solved by using #ifndef (guards) or the #pragma once preprocessior directive.
Yes you can include other c files in your c file.
Or you can tell the compiler to include the file via a command line parameter, then it builds all C files as one thing, this way the compiler can compile the files in parallel.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
.c
is source code, human readable, logic..h
is header file, human readable, pre-processor logic, definitions..o
is object file, not human readable, binary format, linker can "concatenate" these and a binary header to get an EXE..a
is a library, binary format, statically linked, has everything it needs inside itself, an EXE can call functions inside directly..so
same as.a
but dynamically linked, it imports functions from other.so
, other.so
can import functions inside, an EXE can call functions inside directly..dll
same as.so
but for Windows..dynlib
same as.so
but for Mac.I dont code C directly, but I use Nim that compiles to optimized C/C++.
Nice and simple thanks Jaun. I can tell your enjoying Nim so I won't probe to much. But I still wonder how I can write a program in c that consists of several, from what you say.
.c
files. I guess.h
files are just for macros and those define statements etc. Not for:Maybe I can include
.c
files into the main.c
file?You can declare functions in header files:
These are used during compilation, where multiple files
A.c
,B.c
,C.c
depend on some given function(s) in fileD.c
. The filesA.c
,B.c
,C.c
can be compiled using the information in the header fileD.h
only, which contains the function name and signature. The real code inD.c
that has the logic you want to run is associated later, during linking.Be careful though, according to the video, you declare a function prototype in the header is clearer, otherwise people like myself would had wrote a real function in the header with logic (which I have done 😳).
Well, there are two terms here which are distinct - declaration, as Nested said, is giving a prototype of a function or a name of a variable.
void f()
Defining is giving the function it's body (the code of the function).
void f() { return; }
The declaration tells the compiler what to expect and a promise that we will give him that exact thing at some point later.
We can use this to our advatange - for instance by declaring all the functions at the top of the file and then defining them bellow, which helps us better organize the file for human reading.
Similarilay, you put the declarations in the header, and the definitions in the .c file.
You can also both declare and define the functions in the header file - these are called header only libraries (many cool ones available online). The problem with this is that if you have A.c, B.c, C.c, all of them will copy-paste all the functions from the h file into the end result, which can cause slower compilation and potential conflicts. This can by solved by using #ifndef (guards) or the #pragma once preprocessior directive.
Yes you can include other c files in your c file.
Or you can tell the compiler to include the file via a command line parameter, then it builds all C files as one thing, this way the compiler can compile the files in parallel.