Re: Pointer-valued function to access inner components



Salvatore <sfilippone@xxxxxxxxxxx> wrote:

Is the following code legal? Specifically, I am referring to the
pointer assignment in the main program. I am getting three different
behaviours from three different compilers....

The pointer assignment is ok. I need to leave pretty soon and don't have
time to adequately peruse the rest of the code.

However, just reading the subject line rings alarm bells. I truly wish
that the standard did not allow pointer-values functions. It does allow
them, but I consider their problems to be far more severe than their
benefits. Pointer-valued functions are extremely error prone, even for
expert users.

If you adopt a style that keeps away from the most problematic
error-prone areas, then you pretty much give up what functions are for.
The thing that most interestingly distinguishes a function from a
subroutne is that you can evaluate a function as part of an expression.
You aren't restricted to just things like y=f(x); you can also have
y=f(x)+42, or whatever. But do that with a pointer-valued function and
you probably introduced a memory leaks or other bug.

Yes, there are isolated cases where you can avoid the problems. But to
me, those cases are too isolated to counter the error-proneness of teh
whole thing.

I do note that you've got generics that have specifics of the same name
as the generic. The standard does allow that, but it wouldn't shock me
if some compilers get as confused by it as I do. (I didn't see at first
that was what was going on).

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Generics for storage, Anonymous method for operations ! ;)
    ... Test combining generics with anonymous methods. ... The idea is to use generics for the storage and anonymous methods for the ... Maybe alternative ways to get branchless code are possible to... ... So external code could use the generic type via a pointer type or so... ...
    (alt.comp.lang.borland-delphi)
  • Re: Pointer to a generic type parameter
    ... I'm new in VC++ and have a question to generics. ... which contains an array of the generic type. ... I wanted to creat a class member which represents the pointer to the ... the C++ compiler can do pointer arithmetic. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Pointer-valued function to access inner components
    ... behaviours from three different compilers.... ... The pointer assignment is ok. ... However I got a whole range of behaviour from different compilers, ...
    (comp.lang.fortran)
  • Re: Why arent you upgrading?
    ... Nope - I use pointer (or more usually TObject) for things where it is ... services and has at least 10 years of production life and you'll see ... let me see if my life feel incomplete without generics. ...
    (borland.public.delphi.non-technical)
  • Re: Components of derived types with pointer attributes
    ... A pointer assignment to a pointer ... > POINTER and TARGET attribute, thus pointers to pointers are not allowed. ... > pointer assignment statement a reference to a pointer variable is always ...
    (comp.lang.fortran)