Is it wrong to build a program with only one . c and several . h file?

Asked

Viewed 35 times

1

I am making a program in C and decided to implement the functions that are declared within the files . h without using. c files of the same name.

I have a design structure similar to that:

/src
..../dir1
......../header1.h
..../dir2
......../header2.h
..../main.c

In the main. c file I do the includes:

#include "../dir1/header1.h"
#include "../dir2/header2.h"

int main(void){
    //chamo várias funções dos headers
}

In my project I do the inclusion of many other headers, I wonder if writing a program like this is a bad practice and also affects the performance, because the compiler could generate a poorly optimized code...

  • No, it’s wrong to do something unnecessarily, so it depends on what you need.

  • 1

    If I understand correctly, you will only have one translation unit (Translation Unit), for small projects, this is not a problem, just as for small projects it is not a problem to have a single file .c. But as the project grows, you will start to encounter serious difficulties if you need to include one header in the other. Perfomance, perhaps, perhaps and perhaps put here, will have a positive impact as it becomes easier for the compiler to make inline functions.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.