Public modifier value for function in C

PUBLIC void main 

This is from kernel.c from a Minix source. What is the meaning of PUBLIC in this case?

+4
source share
4 answers

It is probably defined as follows:

 #define PUBLIC extern #define PRIVATE static 

Oh, just looked in my copy of Tanenbaum. It is defined as:

 #define PUBLIC 

i.e. like nothing. This is just "self-documentation." PRIVATE is determined, as I originally said. They can be found in the source file Minix const.h .

+9
source

Quote from Tanenbaum Design and implementation of Minix Book operating systems Third edition Page 140 paragraph 3

PRIVATE is defined as a synonym for static. Procedures and data that are not specified outside the file in which they were declared are always declared as PRIVATE to prevent them from being visible outside the file in which they were declared. Generally, all variables and procedures should be declared with a local scope, if possible. PUBLIC is defined as a null string. An example from the kernel /proc.c can help make this clear. Ad

PUBLIC void lock_dequeue (rp)

exits preprocessor C as

void lock_dequeue (rp)

static global variables have the scope of the file. Therefore, if you define a global variable or set the static function, they will be visible only inside this file. That is, you can only access those that are inside this file in a multi-file environment.

extern glapals are visible / accessible from outside the file. extern is optional for defining functions, because by default they are visible from outside the file area.

A hash defining these things before PRIVATE and PUBLIC is nothing more than adding an abstraction layer to better interpret and understand what is actually intended. As in OOP design, private and public interpretations, adding the same name indicates what properties they have.

+3
source

I assume that it will be replaced by the preprocessor with another C as (or an empty string).

Try searching after #define with PUBLIC

+1
source

The word PUBLIC implies that it marks a method as part of the "open interface" of the compilation unit, that is, it is a method that can be called from outside the current source file. (This is just an educated guess). As others have noted, PUBLIC is almost certainly a preprocessor macro that expands to some set of relevant keywords / attributes.

0
source

All Articles