Re: About the private member



On Nov 27, 12:53 am, Arne Vajhøj <a...@xxxxxxxxxx> wrote:
Martin Gregorie wrote:
On Wed, 26 Nov 2008 08:01:28 -0800, pek wrote:
OK.. Now I kinda get it. But is there anybody out there that actually
used this type of code? Is it just Java or OO in general? Either case,
where does this help?

I do that all the time in both Java and ANSI C:

----example.c------
include "example.h"      /* contains function prototypes */

int _global;               /* Underscore restricts scope to this file */

void example(int g)
{
   _global = g;
}

int get_global()
{
   return _global;
}

-------------------
which is more or less exactly equivalent to a Java singleton with a
parameterised constructor and a getter. If more than one "instance" is
needed per program, its easy to define the globals in a struct and to
name it with a typedef. The 'constructor' function mallocs space for it
and returns a pointer. It is freed by a "destructor". The pointer is
passed to all the other functions in just the same way that FILE*
pointers get passed to file handling library functions.

I think you'll find a lot of people use a similar approach to writing C..

Its close enough to OO for translating between this form of C source
module and a Java class to be a fairly straight forward process.

Underscore does what ?

I thought you used static for that ?

Arne

Sooooo.... This is not that useful (or cool) as it sounded right?
Indeed, I have only seen this in the equals method.
.