Re: Is MSDN wrong? or I made a mistake? about static member function



"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:ub06b2d78b2ssp2sqhgm24f1n7v04m2muk@xxxxxxxxxx
After real data types were implemented, it was clear that
struct S1 p1;
had a specific meaning and the construct
p1->x;
was complete nonsense (a K&R compiler of the 1970s would have compiled
this and generated
erroneous code), so this is now diagnosed as a syntax error. Similarly,
struct S1 * p1;
p1.x;
was also complete nonsense, and is also an error. Therefore, there is
little, if any,
reason to maintain such bizarre notations. Since I've worked in languages
which were
designed, rather than thrown together, we used just one notation, and the
compiler was
smart enough to figure out what to do. Since there is also no need to
worry, at a
programming level, as to whether or not a heap object or stack/static
object is being
referenced, the whole "."/"->" notation should be abandoned. Languages
like C# and Java
have abandoned it.


On the contrary, p1->x makes it easy to see p1 was allocated on the heap and
needs to be deleted or otherwise memory managed. p1.x does not.

C# further compounds the confusion by having some rule for allocating some
objects on the stack, and some on the heap, and it is not apparent where
your object is. It is necessary to know for deterministic finalization,
something else C# is weak in.

I couldn't care less what the history of the language is, but I find like
the two distinct notations: -> and .


In the case of static members, as already pointed out, static methods are
referenced by
classname.method rather than variable.reference.

Yeah, and in unfamiliar code, sometimes it's not obvious what is the
classname and what is the instance name. Especially in languages like C#
which discourage Hungarian notation! And also it forces you to define the
method within the declaration, so of course the method declaration doesn't
have classname::methodname in it, so you don't see the classname there
either.

-- David



.



Relevant Pages

  • Re: komplexes Problem mit Funktionszeigern
    ... Die Funktion gibt einen struct "by value" zurueck und bei der ... am Borland Compiler, da der Microsoft Compiler ... Man kann Argumente fuer eine Funktion z.B auf dem Stack uebergeben. ... Das funktioniert natuerlich nur fuer "Basis Typen" die in ein Register passen. ...
    (de.comp.lang.c)
  • Re: Naming typedefs
    ... problem that a scalar could be returned in the A register ... to have waste precious cpu cycles copying the struct there ... of the hardware or twentieth century compiler technology. ... # to include the header defining it into every other header (assuming ...
    (comp.unix.programmer)
  • Re: assembly language and reverse engineering
    ... "return arguments to struct pointed to by register" and ... assumptions of CDECL-like conventions (also supports STDCALL, ... arg for handling struct return (slightly compiler, and compiler version, ...
    (alt.lang.asm)
  • Re: HardBound and SoftBound (was "The State of Software")
    ... I will explain to you one last time that the problem is not whether a compiler can generate checks for all buffer overflows. ... By the way, in the last example of such code that I saw, it had been changed to use the address of the struct, not of the first element of the struct: ... to take address of struct rather than address of first element. ... such tricks are used to create a pointer which is then passed on. ...
    (comp.arch)
  • Re: C++ in ternms of C
    ... >about class and struct difference. ... How is the private and public part ... I tried to analise the ASM file produ ced my the VC++ compil er. ... >epresented by the c++ compiler in translation to intermediate stage. ...
    (microsoft.public.vc.language)