Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C, what does "public" mean when put before a global variable?

Tags:

c

I'm going through the source code of the "less" unix tool by Mark Nudelman, and the beginning of main.c has many of the following:

public int  logfile = -1;
public int  force_logfile = FALSE;
public char *   namelogfile = NULL;

etc. in the global scope, before the definition of main(),

What does public mean in this context? And more important, where can I find this information by myself? I searched using countless query combinations, and could not find this information, or any thorough C reference.

like image 518
Tzafrir Avatar asked Aug 09 '09 11:08

Tzafrir


1 Answers

In the file less.h is your answer:

#define public      /* PUBLIC FUNCTION */

It seems like public is only used as a marker for public/global functions and variables. When compiled, it is expanded to nothing.

How to find this information?

  1. Search the .c file from top to the location of the identifier you want more information about
  2. If you do not find any declaration, look for #include directives
  3. Open any included file and look for the declaration of what you are looking for
  4. Repeat from step two for every included file

In this case, that was pretty simple.

like image 54
Timbo Avatar answered Sep 17 '22 16:09

Timbo