Tuesday, May 3, 2016

Digest for comp.lang.c++@googlegroups.com - 25 updates in 2 topics

"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 07:09AM -0700

Why does C++ not allow this syntax on line 3:
 
01: int x, y, z;
02:
03: some_function(&x, &y, &z);
04: // ...
05:
06: void some_function(int& x, int& y, int& z)
07: {
08: // ...
09: }
 
But instead, it requires this syntax on line 3:
 
01: int x, y, z;
02:
03: some_function(x, y, z);
04: // ...
05:
06: void some_function(int& x, int& y, int& z)
07: {
08: // ...
09: }
 
If the usages on line 3 and line 6 are far away, you can't know from
line 3's usage that they are passed by reference without then going to
visit the line 6 function. And even though most editors will provide
that ability readily, it still seems to be a shortcoming in the C++
syntax, and I'm curious if anyone knows the reasoning behind that
decision to hide all visible markup on the line 3 source line to
differentiate it from merely passed parameters?
 
Best regards,
Rick C. Hodgin
Jerry Stuckle <jstucklex@attglobal.net>: May 03 10:14AM -0400

On 5/3/2016 10:09 AM, Rick C. Hodgin wrote:
> differentiate it from merely passed parameters?
 
> Best regards,
> Rick C. Hodgin
 
Because some_function(int& x, int& y, int& z) takes ints as parameters,
and some_function(&x, &y, &x) is passing pointers to ints.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 07:15AM -0700

On Tuesday, May 3, 2016 at 10:09:35 AM UTC-4, Rick C. Hodgin wrote:
> syntax, and I'm curious if anyone knows the reasoning behind that
> decision to hide all visible markup on the line 3 source line to
> differentiate it from merely passed parameters?
 
They could've used this syntax, for example, to differentiate it from
the & address-of value:
 
01: int x, y, z;
02:
03: some_function(@x, @y, @z);
04: // ...
05:
06: void some_function(int& x, int& y, int& z)
07: {
08: // ...
09: }
 
It's just confusing on the line 3 reference because those values can
be updated, but there's no visible way to know it without going through
the manual investigation of inquiring of each parameter. I.e., it
seems to be a notable syntax shortcoming.
 
Best regards,
Rick C. Hodgin
scott@slp53.sl.home (Scott Lurndal): May 03 02:34PM


>If the usages on line 3 and line 6 are far away, you can't know from
>line 3's usage that they are passed by reference without then going to
>visit the line 6 function.
 
I've never cared much for C++ reference variable for this very
reason, myself.
Jerry Stuckle <jstucklex@attglobal.net>: May 03 01:04PM -0400

On 5/3/2016 10:15 AM, Rick C. Hodgin wrote:
> seems to be a notable syntax shortcoming.
 
> Best regards,
> Rick C. Hodgin
 
They *could* have done a lot of things. But your method violates the
concept of a reference - not having to use special syntax in the code to
pass or use the reference. The only way you can tell if you have a copy
or a reference is to look at the function declaration/definition.
 
I don't argue that '&' is overused, but that's what they chose.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 10:26AM -0700

On Tuesday, May 3, 2016 at 1:04:21 PM UTC-4, Jerry Stuckle wrote:
> They *could* have done a lot of things. But your method violates the
> concept of a reference - not having to use special syntax in the code to
> pass or use the reference.
 
I WANT to use special syntax to pass by reference. I want it to show up
in source code so I know it's a reference rather than a value pass.
 
Best regards,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 10:28AM -0700

On Tuesday, May 3, 2016 at 1:26:33 PM UTC-4, Rick C. Hodgin wrote:
> > pass or use the reference.
 
> I WANT to use special syntax to pass by reference. I want it to show up
> in source code so I know it's a reference rather than a value pass.
 
To be clear:
 
Pass-by-reference has legitimate value on its merits. It's a desirable
asset to have in a programming language. It just needs some syntax
tweaking to be readily usable (as Scott indicated).
 
In my opinion, the value comes in its utility, not in its current syntax.
 
Best regards,
Rick C. Hodgin
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: May 03 06:55PM +0100

On Tue, 3 May 2016 10:26:22 -0700 (PDT)
> > the code to pass or use the reference.
 
> I WANT to use special syntax to pass by reference. I want it to show
> up in source code so I know it's a reference rather than a value pass.
 
"I WANT".
 
Its original purpose was as I understand it to permit efficient operator
overloading with a natural syntax. A little googling would have led you
here: http://www.stroustrup.com/bs_faq2.html#pointers-and-references
 
If you want a special syntax, use pointers. They have been there since
the beginning.
Paavo Helde <myfirstname@osa.pri.ee>: May 03 09:32PM +0300

On 3.05.2016 20:26, Rick C. Hodgin wrote:
>> pass or use the reference.
 
> I WANT to use special syntax to pass by reference. I want it to show up
> in source code so I know it's a reference rather than a value pass.
 
Most class type objects are passed by reference. What you actually want
to show up in the source is pass by non-const reference.
 
What you can do is something like:
 
#include <iostream>
 
template<typename T>
class byref {
public:
T& ref;
operator T& () {
return ref;
}
explicit byref(T& ref): ref(ref) {}
};
 
template<typename T>
byref<T> ref(T& x) {
return byref<T>(x);
}
 
void some_function( byref<int> x) {
++x;
}
 
int main() {
 
int y = 1;
some_function(ref(y));
std::cout << y << "\n";
}
 
A believe a semi-decent compiler should be able to optimize the
templates away so there would be no runtime penalties.
 
hth
Paavo
Melzzzzz <mel@zzzzz.com>: May 03 08:36PM +0200

On Tue, 3 May 2016 07:09:14 -0700 (PDT)
> differentiate it from merely passed parameters?
 
> Best regards,
> Rick C. Hodgin
 
Operator overloading. Having c = a + b; is more convenient then
c = &a + &b;
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 11:44AM -0700

On Tuesday, May 3, 2016 at 1:56:16 PM UTC-4, Chris Vine wrote:
> here: http://www.stroustrup.com/bs_faq2.html#pointers-and-references
 
> If you want a special syntax, use pointers. They have been there since
> the beginning.
 
My position is that references have utility in that you don't need to
check if they're NULL, but they still operate the same way as a pointer
under the hood, updating remote data. They also require less syntax on
use in the target function, which is desirable while still carrying out
remote data assignment. There's just no way to know if something is a
reference or not without additional interrogation of the source code.
 
Best regards,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 11:50AM -0700

On Tuesday, May 3, 2016 at 2:32:46 PM UTC-4, Paavo Helde wrote:
> }
 
> A believe a semi-decent compiler should be able to optimize the
> templates away so there would be no runtime penalties.
 
What's wrong with:
 
void some_function(int& x) {
++x;
}
 
int main() {
int y = 1;
some_function(@y);
std::cout << y << "\n";
}
 
??
 
Why the need for the additional complexity?
 
-----
Anyway, my question was, "What was their thinking?" and I think I see
what it is now. I just happen to disagree with it.
 
Best regards,
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 11:54AM -0700

On Tuesday, May 3, 2016 at 2:36:40 PM UTC-4, Melzzzzz wrote:
> Operator overloading. Having c = a + b; is more convenient then
> c = &a + &b;
 
I can see utility in that syntax, but while it is a pass-by-reference,
it's more pass-by-const-reference, where the values of a and b won't
be updated. So, why not have that syntax for values that are passed
by reference and not updated, but then allow or require the other
syntax when they could potentially be updated?
 
c = @a + @b;
 
In this case, a and/or b could possibly be updated. And in this case
they could not:
 
c = a + b;
 
Because in the case where there is no @ in use for a by-ref usage, it
is really just the equivalent of the thing being passed by pointer, but
without the extra syntax requirements on its use as the compiler does
all of that for you invisibly.
 
Best regards,
Rick C. Hodgin
"K. Frank" <kfrank29.c@gmail.com>: May 03 11:57AM -0700

Hi Rick!
 
On Tuesday, May 3, 2016 at 1:56:16 PM UTC-4, Chris Vine wrote:
> here: http://www.stroustrup.com/bs_faq2.html#pointers-and-references
 
> If you want a special syntax, use pointers. They have been there since
> the beginning.
 
To touch on what Paavo said, const references (different
from your example) don't really raise the same issue.
 
// could pass ints by value
// void some_function(int x, int y, int z);
// or we could pass ints by const reference
void some_function(const int& x, const int& y, const int& z);
 
// client code neither knows nor cares -- some_function
// promises not to modify x, y, or z through the reference
some_function(x, y, z);
 
Your point about non-const references is fully valid:
 
void some_function(int& x, int& y, int& z) { z++; }
some_function(x, y, z); // surprise! z gets modified
 
Should C++ permit this? Maybe not, but it's not high on my
list of things to worry about.
 
But Chris makes a good style suggestion: Pass by pointer
(not by non-const reference) if the function might modify
those arguments. (This is what I generally do. I either
"forbid" the use of null -- and other invalid -- pointers,
or test for them.)
 
 
Happy Hacking!
 
 
K. Frank
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 12:02PM -0700

On Tuesday, May 3, 2016 at 2:57:14 PM UTC-4, K. Frank wrote:
> those arguments. (This is what I generally do. I either
> "forbid" the use of null -- and other invalid -- pointers,
> or test for them.)
 
It's what I do too, but I'm thinking the extra syntax requirements and
dereferencing steps are a little obtuse and could be cleaned up by using
the const reference in the case of mere usage (for structs and objects
mostly, but theoretically for fundamental types as well), and for non-const
references, use something like the @x syntax which also maintains the
cleaner syntax on use, as well as the non-need to test if the passed ptr
is NULL before using it.
 
It just seems like there would be a win-win there if the @x syntax were
introduced, to indicate visually that it is a pass-by-ref, and that its
contents could be updated, while also affording the non-pointer usage,
which can make source code cleaner at times.
 
> Happy Hacking!
> K. Frank
 
:-)
 
Best regards,
Rick C. Hodgin
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: May 03 08:05PM +0100

On Tue, 3 May 2016 11:44:53 -0700 (PDT)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> wrote:
[snip]
> carrying out remote data assignment. There's just no way to know if
> something is a reference or not without additional interrogation of
> the source code.
 
You have a position. It's a trade off. You want someone summing two
complex numbers to write @a + @b, instead of a + b. I don't, nor
apparently did the language designers.
 
There may well be other languages which suit you better: perhaps one
which passes all objects by reference, so there is no need to look it
up. There are plenty which work that way (probably more do than don't).
Gareth Owen <gwowen@gmail.com>: May 03 08:09PM +0100

>>visit the line 6 function.
 
> I've never cared much for C++ reference variable for this very
> reason, myself.
 
I think its a very good reason to use non-const references as function
arguments sparely, and only with a function name that implies what
mutations take place.
 
e.g.
increment(x); // no need to see the prototype void increment(int&);
 
void transpose(Matrix &);
 
is probably better than
 
Matrix transpose(const Matrix&);
 
if memory is tight relative to the size of your matrices.
 
I seem to recall Scott Meyers suggesting that if you're going to do a
memory allocation for a large object, you might as well get it done early:
 
Matrix transpose(Matrix);
 
const references are a different kettle of fish, because at the call
site you (usually) don't care if its pass-by-value or
pass-by-const-reference (or when you do care, you often want the const
reference version).
Gareth Owen <gwowen@gmail.com>: May 03 08:11PM +0100


> Pass-by-reference has legitimate value on its merits. It's a desirable
> asset to have in a programming language.
 
How does your suggestion
 
some_function(@x, @y, @z);
void some_function(int& x, int& y, int& z);
 
differ from
 
some_function(&x, &y, &z);
void some_function(int* x, int* y, int* z)
 
?
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: May 03 12:16PM -0700

On Tuesday, May 3, 2016 at 3:12:07 PM UTC-4, gwowen wrote:
 
> some_function(&x, &y, &z);
> void some_function(int* x, int* y, int* z)
 
> ?
 
In important ways related to use:
 
some_function(@x, @y, @z);
 
void some_function(int& x, int& y, int& z)
{
// Use immediately with cleaner syntax
other_thing(x + y + z);
}
 
Versus:
 
some_function(&x, &y, &z);
 
void some_function(int* x, int* y, int* z)
{
// Make sure pointers aren't NULL
if (x && y && z)
other_thing(*x + *y + *z);
}
 
Best regards,
Rick C. Hodgin
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: May 03 08:18PM +0100

On Tue, 03 May 2016 20:11:55 +0100
 
> some_function(&x, &y, &z);
> void some_function(int* x, int* y, int* z)
 
> ?
 
His argument elsewhere in this thread is that references avoid needing
to check for NULL, so ought to exist but only with a pointer-like
syntax.
 
I think that is a weak advantage for the additional syntactic
complexity that he proposes. In any event, Stroustrup presumably did.
Jerry Stuckle <jstucklex@attglobal.net>: May 02 08:07PM -0400

On 5/2/2016 5:07 PM, Ian Collins wrote:
>>> meet the original requirement.
 
>> Show where it violates the C standard.
 
> Where did I say it did?
 
Show where it violates the C standard.
 
>> And cross-compilation, by definition, is implementation specific. It is
>> not part of the C standard, and not supported by all compilers.
 
> Where did I say it was?
 
Where did you say cross-compilation was part of the C standard?
 
>> change the rules rather than admit I'm right.
 
> David said "There is no implementation-independent way to do this in C
> or C++". Cross compilers are implementations.
 
Where is there ANY PROGRAM WHICH DOES USABLE WORK which is COMPLETELY
implementation-independent?
 
Implementation-independent in C does NOT mean *exactly the same code*
has to run in *all circumstances*.
 
But trolls like you don't understand that.
 
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Jerry Stuckle <jstucklex@attglobal.net>: May 02 08:08PM -0400

On 5/2/2016 5:11 PM, Gareth Owen wrote:
 
>> What a troll. The technique is implementation independent. That
>> doesn't mean the code has to be 100% implementation dependent.
 
> Seek professional help.
 
Definitely, you need to do so - as all trolls do.
 
But then trolls think they are psychiatrists, as well as experts at
programming. You have proven yourself to be neither. But you
definitely are a troll.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Ian Collins <ian-news@hotmail.com>: May 03 12:16PM +1200

On 05/03/16 12:07, Jerry Stuckle wrote:
 
>>> Show where it violates the C standard.
 
>> Where did I say it did?
 
> Show where it violates the C standard.
 
I can see that you are a fan of pantomime.
 
>>> not part of the C standard, and not supported by all compilers.
 
>> Where did I say it was?
 
> Where did you say cross-compilation was part of the C standard?
 
I don't know, where did I?
 
>> or C++". Cross compilers are implementations.
 
> Where is there ANY PROGRAM WHICH DOES USABLE WORK which is COMPLETELY
> implementation-independent?
 
No one asked for a program that does useful work. This evasion tactic
won't work.
 
> Implementation-independent in C does NOT mean *exactly the same code*
> has to run in *all circumstances*.
 
> But trolls like you don't understand that.
 
Ah good, name calling. Always a good three year old's response when
they can't provide a coherent argument.
 
--
Ian Collins
Jerry Stuckle <jstucklex@attglobal.net>: May 02 08:35PM -0400

On 5/2/2016 8:16 PM, Ian Collins wrote:
 
>>> Where did I say it did?
 
>> Show where it violates the C standard.
 
> I can see that you are a fan of pantomime.
 
I see you continue to evade the question because you can't answer it.
 
 
>>> Where did I say it was?
 
>> Where did you say cross-compilation was part of the C standard?
 
> I don't know, where did I?
 
I see you continue to evade the question because you can't answer it.
 
>> implementation-independent?
 
> No one asked for a program that does useful work. This evasion tactic
> won't work.
 
I see you continue to evade the question because you can't answer it.
 
 
>> But trolls like you don't understand that.
 
> Ah good, name calling. Always a good three year old's response when
> they can't provide a coherent argument.
 
No, just the truth. If it acts like a duck, walks like a duck and
quacks like a duck, chances are it is a duck.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
scott@slp53.sl.home (Scott Lurndal): May 03 12:42PM


>I was exposed to a bunch of machines and environments all at once
>through the University of Delaware:
 
>- CDC Cyber running PLATO
 
Yep. DnD, Empire and Notes!
 
>- Burroughs B6700 running CANDE
 
Was an OS engineer for the Burroughs B[234]900 running MCP
(and CANDE [Command And Edit] for timesharing). There is a
fellow in Tasmania who is developing a B6700 simulator.
 
http://www.retrocomputingtasmania.com/home/projects/burroughs-b6700-mainframe
(with fond memories of the TD-830's in the foreground).
 
>- PDP 11/70 running RSTS/E
 
11/45 running RSX-11M
 
>- PDP 11/70 running Unix (don't remember what version, 4 perhaps?)
 
11/34 running Unix V6.
 
>- DECsystem 10 running TOPS-10
>- HP 2000 running a BASIC shell
 
HP-3000 running MPE (using SPL).
 
ITEL AS/6 running MVS.
 
 
>I taught myself basic on the HP 2000 using a series of programs in
 
I hand disassembled the TSS8 Basic Interpreter to help learn
how it worked circa 1975/6.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: