Topic: Assignment to function name -- any meaning?


Author: James Kuyper <kuyper@wizard.net>
Date: 1997/04/21
Raw View
David A. Cuthbert wrote:
...
> int  myFunction(void)  throw() {
>         myFunction = 8;         // note lack of declaration.
>         return myFunction;
> }
>
> Does this have any meaning in C++?

The short answer is, no. However, I gather that you are suggesting that
this be allowed, so you don't have to define an additional variable name
for storing the return value. This is a bad idea. It means that a
function name can be used both as an rvalue and as an lvalue, with
completely different meanings in each case. In particular, I'd hate to
think about what the following could mean:

int (*funcptr)(void);

int myFunction(void)
{
 funcptr = myFunction = 8;
 return myFunction;
}

Of course this code would either be illegal, or equivalent to:
 myFunction=8, funcptr=myFunction;
but I don't like it either way.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: "Paul D. DeRocco" <strip_these_words_pderocco@ix.netcom.com>
Date: 1997/04/18
Raw View
David A. Cuthbert wrote:
>
> However, I was wondering if assignment to an object using the name of
> the function has any meaning currently.  Specifically, something like:
>
> int  myFunction(void)  throw() {
>         myFunction = 8;         // note lack of declaration.
>         return myFunction;
> }
>
> Does this have any meaning in C++?

No, it doesn't. I recall some other language in which the function name
was implicitly a variable, and you'd return a value by setting that
variable and then returning. I think it may have been Basic. Anyway, it
was one of those crappy languages that I always hated writing.

--

Ciao,
Paul D. DeRocco

(Please send e-mail to mail:pderocco@ix.netcom.com instead of the
return address, which has been altered to foil junk mail senders.)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: rmashlan@r2m.com (Robert Mashlan)
Date: 1997/04/18
Raw View
dacut@henry.ece.cmu.edu (David A. Cuthbert) wrote:

>However, I was wondering if assignment to an object using the name of
>the function has any meaning currently.  Specifically, something like:
>
>int  myFunction(void)  throw() {
> myFunction = 8;  // note lack of declaration.
> return myFunction;
>}
>
>Does this have any meaning in C++?

Yes - although the above wouldn't compile without a cast, the
following would be valid C/C++:

void*  foo(void)
{
   return foo;
}



---
Robert Mashlan  R2M Software  rmashlan@r2m.com
Internet Resources for Windows Developers http://www.r2m.com/windev/
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: csc@atl-intl.com
Date: 1997/04/20
Raw View
For what it is worth, among the languages that do have
this construction is Fortran.

In article <5in9an$9s1@fs7.ece.cmu.edu> dacut@henry.ece.cmu.edu (David A.
Cuthbert) writes:

>However, I was wondering if assignment to an object using the name of
>the function has any meaning currently.  Specifically, something like:

>int  myFunction(void)  throw() {
>        myFunction = 8;         // note lack of declaration.
>        return myFunction;
>}

>Does this have any meaning in C++?
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: dacut@henry.ece.cmu.edu (David A. Cuthbert)
Date: 1997/04/17
Raw View
I've been thinking about the return value optimization problem in the
back of my head lately.  In particular, fine grain control (i.e.,
programmer hints) seems difficult to express syntactically (through
whatever language extension).  I haven't used it, but I believe that
g++ uses something like:
int  myFunction(void)  throw() return(someVar) {
 someVar = 8;
 // ...
 return someVar;
}

However, I was wondering if assignment to an object using the name of
the function has any meaning currently.  Specifically, something like:

int  myFunction(void)  throw() {
 myFunction = 8;  // note lack of declaration.
 return myFunction;
}

Does this have any meaning in C++?

(FWIW:  I'm not sure about this idiom, but I don't think I really like
it.  It obscures the return value somewhat, and also has a syntactic
ambiguity if the function returns a class for which operator () is
defined -- how do you tell between this and a recursive call into the
function?)

--
David A. Cuthbert (henry.ece.cmu.edu!dacut)
Graduate Student, Electrical and Computer Engineering
Data Storage Systems Center, Carnegie Mellon University
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]