Questions tagged [c-header]

In modern C, header files are crucial tools that must be designed and used correctly. They allow the compiler to cross-check independently compiled parts of a program.

34 questions
226
votes
4 answers

Creating your own header file in C

Can anyone explain how to create a header file in C with a simple example from beginning to end.
Anuragdeb3
  • 2,299
  • 3
  • 14
  • 4
7
votes
2 answers

Is it wrong to place inline functions in C headers?

I am building a C project for several compilers, some of which are legacy compilers which don't seem to have link time inlining support, so it seemed logical to place static inline functions directly in headers and actually have each translation…
Lou
  • 4,244
  • 3
  • 33
  • 72
3
votes
3 answers

C: How can I know what header do I need for the functions I am using?

Example program in C (without headers): int main() { printf("\nHello World\n"); } How can I know what include header (example: #include ) should I prepend?
Sopalajo de Arrierez
  • 3,543
  • 4
  • 34
  • 52
2
votes
1 answer

C header declaration for generics (macro)

I am unsure about where to write the declaration and the call of a macro that replaces the code with a function. I do not really know if I should write the macro to the .h or .c file. Before reading some stuff on the best ways to create libraries, I…
std124_lf
  • 134
  • 2
  • 9
2
votes
1 answer

How can a C function like time() be called without its header file?

According to documentation I checked, time_t time(time_t *seconds) is declared under header file. Yet when I run this code: #include #include int main() { srand(time(NULL)); printf("%d",rand()); return…
2
votes
1 answer

Hide private fields of a Rust lib when generating its C header

I am making a Rust library that contains the following code: pub mod my_module{ use std::os::raw::{c_int, c_double}; use std::collections::HashMap; struct MyPrivateClass { my_parameter:c_int } (...) #[repr(C)] …
Kyrill
  • 227
  • 1
  • 11
2
votes
1 answer

Macros defined in time.h not recognized

Originally, I wanted to cast a struct timeval to a timespec one. At first, it did not seem difficult, as a solution is proposed there: Is there a standard way to convert a struct timeval into a struct timespec? A macro, TIMEVAL_TO_TIMESPEC is…
S. Humeau
  • 23
  • 7
1
vote
1 answer

How to write a C header file properly so that a function declared by that header file can be linked without any error?

I am trying to write a C header file in this manner: // header.h #ifndef HEADER_H #define HEADER_H extern int add(int a, int b); #endif // header.c #include "header.h" int add(int a, int b) { return (a+b); } Now suppose I have a main.c file…
arijitkd
  • 103
  • 7
1
vote
1 answer

struct datatype is defined in the .c file and it is used in the header file while the normal situation has to be the opposite

The definition of struct datatype should be in the header file and not the opposite. This is what I understand while this project does the opposite in this special case. What drive the contributor to decide to do so and why ? I am aware it is a…
1
vote
1 answer

Can the python interpreter tell me where its header files are?

In debian/CentOS systems, python's excutable, header and library files are organized like: /usr/(local/|)/bin/python /usr/(local/|)/include/python-$version$/ /usr/(local/|)/libs But on Windows, the folder structure is a bit different C:\\Program\…
Catherine Holloway
  • 739
  • 1
  • 7
  • 20
1
vote
0 answers

Error: We found the libraries for libevent, but we could not find the C header files

I´m trying to install an old Tor version which requires a libevent devel package. I have downloaded a devel package correctly, but and when I run ./configure --with-libevent-dir=/libevent/lib/x86_64-linux-gnu/, I´m getting this output: We found the…
Antonio Sanchez
  • 381
  • 1
  • 3
  • 11
1
vote
2 answers

Error when compiling olcPixelGameEngine with g++

I'm trying to use OneLoneCoder's olcPixelGameEngine, but when I try to compile my file (g++ -o YourProgName YourSource.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17), I get the error: fatal error: dwmapi.h: No such file or directory I use g++…
biskit
  • 11
  • 3
0
votes
0 answers

Adding library in CMake with many subfolder

I am starting with the raspberry pi pico and the visual studio code in windows. I am practising with the pico examples coming in the SDK V1.5. What I want to try in this example is to add a new level of folder with an .C and .h files in it. The…
Rarodron
  • 1
  • 2
0
votes
1 answer

How does `math.h` refer to functions like `sin` or `cos`?

I see a plenty of similar questions, which are duplicates (like 12074147), but most of them are concerned with mathematical functions implementation. My question is more about C standard headers, like this one: #include What I'd be happy…
garej
  • 508
  • 1
  • 8
  • 24
0
votes
0 answers

Can one derive Swift functions from the (C convention) functions in a dylib using knowledge from their prototypes in the C .h file?

I have some dynamic libraries making available over 200 functions via C calling conventions. I have no access to the source. I'd like to provide these as functions callable by Swift. Currently I am making each function from the dylibs available…
RamsayCons
  • 71
  • 3
1
2 3