Re: Forward declarations to static variables



> It's a declaration and a *tentative* definition.

That is clear, thanks.
Is it defined by C89 and supported by all C compilers (I don't care
about pre-ANSI ones) ?

> Why can't you just move the declaration to the top of the file?

The real code is like this:

#include <xmms/plugin.h>

extern InputPlugin mod; // <-- I'll change it to static

static void init(void)
{
// ...
}

static int is_our_file(char *filename)
{
// ...
}

static void play_file(char *filename)
{
// ...
// (I use mod.output here)
}

static void pause(short paused)
{
mod.output->pause(paused);
}

static void stop(void)
{
// ....
}

static int get_time(void)
{
// ...
}

static InputPlugin mod = {
// ...
init,
NULL,
NULL,
is_our_file,
NULL,
play_file,
stop,
pause,
NULL,
NULL,
get_time,
// these are filled by XMMS at runtime (this includes the "output"
field):
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

// this is exported from the compiled *.so:
InputPlugin *get_iplugin_info(void)
{
return &mod;
}

Of course I could make forward declarations of my static functions,
for example:

static void pause(short paused);

(I'm sure this is a declaration and never a definition)
and then define "mod" at the top, but as you can see there are several
static functions while there's just one "mod".

> For portability, you'll probably need to remove all references to 'static'.

Ehm, what?

> 'static' on variables is supposed to mean that it doesn't get exported to
> the linker.

This is exactly what I want.

> You seem to misunderstand the whole system.

No.

Thanks,
Piotr

.



Relevant Pages