0

I am interested to know whether this would be a possibility of working without any issues?

#ifndef _HEADERS_ALL_
#define _HEADERS_ALL_

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Directory Queue headers */
void init_dir_queue (void);
void enqueueDir (char *name);
int dequeueDir (char *name);
void show_dir_queue (void);
/* we will only use one error function to call for both Queues */
void error (char *msg);

/* File Queue headers */
void init_file_queue(void);
void enqueueFile(char* path);
int dequeueFile(char* path);
void show_file_queue(void);

#endif // !1

And just include in main.c:

#include "headers.h"

Declarations are in dirQueue.c and fileQueue.c.

Will compile using: gcc main.c fileQueue.c dirQueue.c -o main

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • 2
    Yes, but you might not want to do so in practice. It means every source file will include every header, even if they don't need most of them (and very few source files will require even most of the headers, let alone all of them). – Jonathan Leffler Apr 15 '21 at 05:03
  • Note that you should not, in general, create function, variable, tag or macro names that start with an underscore. Part of [C11 §7.1.3 Reserved identifiers](https://port70.net/~nsz/c/c11/n1570.html#7.1.3) says: — _All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use._ — _All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces._ See also [What does double underscore (`__const`) mean in C?](https://stackoverflow.com/q/1449181) – Jonathan Leffler Apr 15 '21 at 05:03
  • Just try it. But I would guess this works. But even if you can do it, should you do it? No, you shouldn't do that, cause it's bad practice. – paladin Apr 15 '21 at 05:04
  • I see it was just taught and I have tried it but for some reason, ya might be interested in wanting to know what happened. And i am so confused to how is that even possible –  Apr 15 '21 at 05:07
  • Why wouldn't it be possible? `#include` basically copies and pastes the contents of the specified file. – jamesdlin Apr 15 '21 at 05:22
  • 2
    Keep in mind that the `#include` mechanism is very simple: when the preprocessor encounters a `#include` line, it simply reads in the specified file as if the contents of that file had been inserted at that location. So when you add `#include "headers.h"` to your `main.c` file, the program that gets compiled is the same as if you had manually copy-and-pasted the contents of `headers.h` into your `main.c` file at that same line. – Jeremy Friesner Apr 15 '21 at 05:23
  • 1
    Yes. You can do it. The reason you don't want to do it is because it takes time to compile code and the more that has to be compiled the longer it takes. I have a program that takes more than 5 minutes to compile - if each source file included all the headers it would take even longer. But for a program that takes less than 10 seconds to compile it doesn't matter at all. – Jerry Jeremiah Apr 15 '21 at 05:23
  • @Jeremy Friesner Very interesting sir I will remember this and thank you for sharing –  Apr 15 '21 at 05:26
  • If you get any problems then it probably is because "Declarations are in dirQueue.c and fileQueue.c.", at least if they are also used/needed elsewhere. They should not be. Declarations go into headers, code goes into code files. You are not including .c files anywhere, are you? – Yunnosch Apr 15 '21 at 06:05
  • 1
    "it was just taught" Hmm, question your teacher about this and applicability to large, multi file projects. "but for some reason," I feel that something is missing there. Did you drop part of that sentence? "ya might be interested in wanting to know what happened" Yes, please report about what happened. – Yunnosch Apr 15 '21 at 06:08

0 Answers0