[cs631apue] questions about openmax.c

Jan Schaumann jschauma at stevens.edu
Wed Sep 17 09:59:09 EDT 2014

zding4 <zding4 at stevens.edu> wrote:

> Why is it the "static int"?

In addition to what Sadia wrote, "static" also allows you to scope a
global variable to just one source file.
explains both use cases and contains links to more information.

Now as to why this program uses "static" here... I'm afraid I'd have to
guess.  The code originated in the first edition of the Stevens book,
and if I recall correctly it was offered there as part of a library, not
a stand-alone program as we have used it.  As that, it might have been
useful to avoid conflicts with other source files that might also have a
global 'openmax'.

When the code was taken from the book as a standalone example (probably
around ten years ago or so, when I first started teaching this class),
it morphed into a function, but retained the "static", even though in
our code example that is not useful (albeit neither harmful).

I've updated the code online to remove the 'static' to avoid confusion
in the future.


More information about the cs631apue mailing list