Wireshark-bugs: [Wireshark-bugs] [Bug 5048] VeriWave encapsulation type and WaveAgent protocol -
Date: Mon, 25 Oct 2010 15:30:23 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5048

--- Comment #14 from Guy Harris <guy@xxxxxxxxxxxx> 2010-10-25 15:30:22 PDT ---
I don't have my C standard handy, so I might not be getting the terminology
exactly right, but there's the storage *scope* of a variable - file or global -
and there's the storage *duration* of a variable - static, automatic, and
allocated.

"static int x" says that "x" has file scope - i.e., it's accessible only to
code in the source file that contains that definition - and static storage
duration - i.e., it exists for as long as the program is running.

"int x" at the top level, or "extern int x", says that "x" has global scope -
i.e., it's accessible to code outside the source file with that definition -
and static storage duration.

"int x" inside a function says that "x"  has automatic storage duration - i.e.,
each active call to the function has its own instance of "x", which goes away
when the function returns.

"int *x = malloc(sizeof (int));" creates an int, pointed to by x, that has
allocated storage duration - i.e., it exists until you free it.

The "static" I was referring to was the storage duration - getting rid of the
"static" keyword for a variable at the top level doesn't change that.  Private
mutable data in a Wiretap module must have allocated storage duration, and one
instance must be allocated for each open capture file.  (Private *immutable*
data - for example, a lookup table of some sort - can have static storage
duration.)

I.e., *ALL* the "various internal variables" must be members of a structure,
one instance of which is allocated for each successful call to vwr_open(), with
vwr_open() storing a pointer to that structure in wth->priv.  All other
routines will refer to those variables by casting wth->priv to a pointer to
such a structure and referring to the appropriate member of the structure, and
you will need to have a vwr_close() routine to free up that structure when the
file is closed.

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.