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:

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 ?


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

Relevant Pages

  • Re: The Java no pointer big fat lie!
    ... Does Java have auto variables that construct and destruct by scope? ... Are object references a native memory pointer or an abstracted ... > and reference) ...
  • Re: The Java no pointer big fat lie!
    ... > Whenever I read a Java book and it states that Java has no pointers, ... can't do pointer arithmetic, ie pointer+20 is impossible in Java. ... of the object they reference but to an intermediate which does that. ... A pointer is a memory address in C, no more, no less. ...
  • Re: How java passes object references?
    ... Which everybody knows, it doesn't in Java. ... The reason I think this is a useful clarification is that when you got to the part about how passing by reference might work, it seems you went off track at least partly because you didn't understand the nature of the above. ... is a pointer pointing at the memory block. ... Assignments to local variables, or even to class members, do not allocate memory. ...
  • Re: Forth is broken by culture?
    ... new language, one question I might ask myself is "what types of bugs ... I worked on a Java project a while back with a very productive C++ ... It was because there were no pointer ... programs can dereference null pointers causing potentially catastrophic, ...
  • Re: OT:Re: The End of C++
    ... What I was trying to say, is that if you are to criticise ... I personally very much dislike coding using Java ... code that access memory through an unbounded pointer into an array. ...