Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a "private header" in C?

I've been learning C recently, and in one of my textbooks I found a reference to a file with the ".r" extension. Now, as you can imagine, googling "r" or "file extension r" is not productive, so I wonder if you could help me out.

It appears in the following code block

#include "new.r"

static const struct Class _String = {
  sizeof(struct String),
  String_ctor, String_dtor,
  String_clone, String_differ
};

const void * String = & _String;

The author mentions that it is a "private header", but I wish he could have been more clear as to what exactly that is.

like image 586
Ziggy Avatar asked Jun 06 '09 00:06

Ziggy


People also ask

What is a private header?

Public headers are those needed by the users of the library. Private headers are those needed to compile the library, but which are not needed by library users.

What are headers in C?

In C language, header files contain the set of predefined standard library functions. You request to use a header file in your program by including it with the C preprocessing directive “#include”. All the header file have a '. h' an extension. By including a header file, we can use its contents in our program.

What is custom header file in C?

header files are simply files in which you can declare your own functions that you can use in your main program or these can be used while writing large C programs. NOTE:Header files generally contain definitions of data types, function prototypes and C preprocessor commands.


1 Answers

As far as I can tell from various open source projects I've seen, private headers are headers intended to be used only by a particular piece of code (a file or multiple files). They are useful when, for example, some files need access to each other's symbols/declarations, but those symbols/declarations shouldn't be accessed from other code. Or they can be used to split prototypes out of .c files.

Global or normal headers are usually stored in a special 'include' directory, while private headers stay near the specific code they serve.

As for the 'dot r' extension, I've never heard of it before. The private headers I've seen are named 'dot h', like all others.

like image 88
Eduard - Gabriel Munteanu Avatar answered Sep 22 '22 15:09

Eduard - Gabriel Munteanu