Another spinoza challenge

K

Kenny McCormack

spinoza1111 said:
This is because your goal is to "prove" that people don't know things
that they actually do know, but fail to express your way. This, in
turn, is because you're here to destroy people, not to make a
contribution.

Water still wet. Francisco Franco: still dead.
 
S

spinoza1111

...
 > When a function parameter is passed by reference, the value of its Von
 > Neumann address is passed to the function. Changes to this value are
 > also lost, but it can be "dereferenced" using asterisk as a prefix
 > operator to access the calling procedure's copy of the parameter to
 > change this copy.

Hm.  So in the Fortran code:
      SUBROUTINE SUB(A)
      A = 1.0
      RETURN
      END
      SUBROUTINE SUB1(C)
      REAL A
      CALL SUB(A)
      C = A
      RETURN
      END
there is no pass by reference?

I was talking about C. Fortran provides Visual Basic's by reference
call but as a default, and here you don't get the address. Please tell
us more about Algol and Dijkstra rather than pursue these sterile
terminology debates.

In a sense, Humpty Dumpty (and Ferdinand de Saussure) were right. When
I (or preferably, "one") use(s) a word, it does mean exactly what we
choose it to mean. The only issue is participation in a community, but
having one's own meanings doesn't prevent this as long as one can
explain oneself and understand another. What short-circuits
communicative reason isn't reconcilable difference in our meanings,
but campaigns of personal destruction and vanity meanings.
 
J

jameskuyper

Dennis said:
If it's only for its own use, then would it be in a public header?

Possibly - if it were used, for instance, in the expansion of some
other macro that is meant to be used by the general public.
 
S

spinoza1111

spinoza1111said:



I defer to your superior experience of being a fat assed misfit, but
such a description is far from appropriate for those C experts who

The very notion of "expertise" in a programming language is nonsense,
since the "expertise" is overfamiliarity with mistakes that stunts the
intellect of the "expert".
frequent this group. You can do all the C tests you like, but it is
here that you will learn precisely what is wrong with those tests and
precisely why.

Not from you, boyo, not from you.
Maybe from Ben and certainly from Dik
But you need to learn from me. Wise up.
 
S

spinoza1111

K&R muddied the waters themselves.  bartc should have illustrated the
point with an array rather than a hypothetical struct syntax:
#include <stdio.h>
void byref(int v[])
{
  v[0] = 42;

int main(void)
{
  int vec[] = {1, 2, 3};
  byref(vec);
  printf("vec[0] = %d\n", vec[0]);
  return 0;

This passes almost every test for "pass by reference" one can think
of.  There is no special syntax in the called function and none
needed at the point of call.  The parameter declaration can even look
like an array.
The only test it fails is that C does not have pass by reference!

That particular test fails completely in my opinion. For true pass-by-
reference to be present, regardless of syntax, I would expect to
receive an object that's functionally identical to the original
object. Even when hiding the pointer away with array notation, it
still isn't pass-by-reference simply because one can't get the size of
the array with any meaningful result.

Neither could one in old Fortran, yet it was still call by reference.
What you're asking for isn't call by reference. It's object oriented
stuff.
A better test would pass a pointer to the array:

#include <stdio.h>

void notbyref ( int v[] )
{
  printf ( "%lu\n", (unsigned long)sizeof v );
  v[0] = 42;

}

void bysimref ( int (*v)[3] )
{
  printf ( "%lu\n", (unsigned long)sizeof *v );
  (*v)[0] = 24;

}

int main ( void )
{
  int vec[] = { 1, 2, 3 };

  notbyref ( vec );
  printf ( "vec[0] = %d\n", vec[0] );
  bysimref ( &vec );
  printf ( "vec[0] = %d\n", vec[0] );

  return 0;

}

At least this way one can argue that the original object is available
such that after dereferencing the pointer, you have the functionally
identical behavior required to be called pass-by-reference. Though it
still requires pointer syntax, the syntax is especially awkward for
this case, and the size of the array needs to be specified explicitly
[1].

Personally, I have no problem with calling C's simulated reference
"pass-by-reference" as long as all parties understand that what really
happens is a pointer is passed by value. I believe that this is an
important distinction to make, and clears up several misconceptions
that result in broken code.

[1] Prior to C99. A VLA in C99 would remove the restriction of an
explicit array size at the function definition level.- Hide quoted text -

- Show quoted text -
 
C

Chris Dollin

spinoza1111 said:
The very notion of "expertise" in a programming language is nonsense,

Don't be silly.
since the "expertise" is overfamiliarity with mistakes that stunts the
intellect of the "expert".

The existence of a fake "expertise" doesn't make real expertise non-existent,
just as the existence of scare quotes doesn't mean everybody is afraid.

--
"There are not enough adjectives in the English Faye,
language to describe how wrong you are." /Questionable Content/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
 
R

Richard Tobin

That particular test fails completely in my opinion. For true pass-by-
reference to be present, regardless of syntax, I would expect to
receive an object that's functionally identical to the original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
object. Even when hiding the pointer away with array notation, it
still isn't pass-by-reference simply because one can't get the size of
the array with any meaningful result.
[/QUOTE]
Neither could one in old Fortran, yet it was still call by reference.

You misunderstand. Read the underlined phrase. In "old Fortran" you
couldn't get the size of the array in the function declaring it; in C
you can.

-- Richard
 
K

Keith Thompson

Richard Heathfield said:
Richard Tobin said:



Well, a /probably/-known gravitational field. It is certainly possible
for a spring balance to be used outside Earth's gravitational field
(and I would not be prepared to bet that it has not been done
already).

Spring balances can show inaccurate masses inside Earth's
gravitational field due to acceleration effects. Try using one in
a moving elevator, or while spinning it around your head, or even
in low Earth orbit.

The implicit assumption is that it's going to be used in an
environment with no significant acceleration relative to the Earth,
without enough applied force to permanently damage the springs,
and at temperatures low enough that the springs don't melt. If you
want to determine something's mass or weight when those assumptions
are violated, you need to find another method.
 
B

Beej Jorgensen

Keith Thompson said:
Spring balances can show inaccurate masses inside Earth's
gravitational field due to acceleration effects. Try using one in
a moving elevator, or while spinning it around your head, or even
in low Earth orbit.

This is why all bathroom scales sold in the US are inscribed with this
warning:

This scale is only accurate in non-accelerating environments close to
the surface of the Earth and does not correct for localized
gravimetric effects. Accuracy in non-terrestrial environments is not
guaranteed. Not for use on trampolines.

-Beej
 
K

Keith Thompson

Beej Jorgensen said:
This is why all bathroom scales sold in the US are inscribed with this
warning:

This scale is only accurate in non-accelerating environments close to
the surface of the Earth and does not correct for localized
gravimetric effects. Accuracy in non-terrestrial environments is not
guaranteed. Not for use on trampolines.

You see, this is the problem with warnings written by non-technical
people. This implies that the scale is *only* accurate in the
specified environment, when in fact there are numerous other
environments (such as a ship in deep space with a continuous 1G
acceleration, or a properly calibrated centrifuge on the surface
of the Moon) where the scale would *also* be accurate.

And where exactly could you expect to find a "non-accelerating
environment"?

If it had simply said that the behavior in other environments is
undefined, the bases would have been covered.

Makes you realize what a difficult job the authors of the C
standard have.
 
P

Phil Carmody

Keith Thompson said:
Now consider the following nearly equivalent C code that emulates
pass-by-reference:

void foo(int *param) {
printf("Previous value of parameter is %d\n", *param);
*param = 42;
}
...
int x = 10;
foo(&x);

To emulate pass-by-reference, I had to (a) pass the address of x
rather than just x (more precisely, the address of x rather than
the value of x) and (b) inside foo, replace each occurrence of
``param'' by ``*param''.

So perl can't pass by reference then, and all the chapters about
clever things you can do with references in books about perl by
Wall and Schwartz and uncle Tom Cobbley should be torn out and
filed alongside Schildt?

When's your book on Perl coming out, I've obviously got a lot to
first unlearn from those perverters of the language and then to
learn from you.

Phil
 
P

Phil Carmody

Dik T. Winter said:
No, the syntax for call by reference and call by name is identical.

An absurd statement. In some languages it's the same, in other
languages it's different.

Phil
 
P

Phil Carmody

Nick Keighley said:
good grief. In what conext does it weigh 10kgs?

Every context apart from those populated by revisionists who
think that they can pervert the meaning of a perfectly standard
word.
"The spare battery on the lunar rover weighs 10kgs"

It kind of matters where you do the weighing as to what that means.

Even on the earth's surface weight varies if you do the measurement
carefully enough. So we *still* don't know if the interviewer was a
mindless pedant or you didn't know some basic physics.

Oh dear. Looks as if you are as wrong as he was. I knew some basic
English - 'weight' is mass - and that's all that matters in this
context. He was pendantic, yes, but basing his pedantry on incorrect
information, the same incorrect information you base your view on.

Phil
 
R

Richard Tobin

Beej Jorgensen said:
This scale is only accurate in non-accelerating environments close to
the surface of the Earth and does not correct for localized
gravimetric effects. Accuracy in non-terrestrial environments is not
guaranteed. Not for use on trampolines.

Have you compared how your scales read in summer and winter?

-- Richard
 
P

Phil Carmody

<off topic:>

Actually, the kilogram is an SI unit of mass.

"Weight" is the force on an object due to the gravitational attraction
between it and the Earth (or another nearby heav(enl)y body).
The SI unit of weight is the Newton (N), 1 N = 1 kg*m/s/s .
The weight of an object equals its mass times the local gravitational
acceleration constant, g (approximately 9.8 m/s/s on the surface of the Earth).

So, instead of saying "it weighs 10 kilograms" it would be more accurate
to say "its mass is 10 kilograms" or "it weighs 98 Newton" (on Earth).

Weight, for nearly a millennium, has been a measure of bulk mass.
For example, food is legally labelled with its "weight", not mass.
If you sell the same mass of produce with a price per unit weight,
it costs the same no matter where it is sold. Why are you failing
to understand concepts that they teach ten-year olds?

I have perfectly good words for concepts like force, why should I
use a word for mass in their place? Its use for gravitational force
is just modern jargon, and it sticks out like a sore thumb as
particularly badly chosen jargon.

Phil
 
P

Phil Carmody

bartc said:
Both my kitchen and bathroom scales have readouts in Kg and g. What
are they measuring, weight, mass or both?

Not enough information, obviously. My guess is force. Why do you
ignore the possibility that it's measuring torque?

Phil
 
J

jameskuyper

Phil said:
Every context apart from those populated by revisionists who
think that they can pervert the meaning of a perfectly standard
word.

Those "revisionists" did their revision centuries ago, and it now
dominates physics and engineering, and has widespread acceptance in
many related disciplines, where that revised meaning (and not yours)
is "perfectly standard". You might not need to pay attention to the
revision if you're not working in one of those fields, but doing so is
essential if you are to work in one of them.
Oh dear. Looks as if you are as wrong as he was. I knew some basic
English - 'weight' is mass

In math/science/engineering contexts, the "weight" of an object does
not refer to it's mass, but to the force on that object due to
gravity. In a few standard terms (such as "atomic weight", or
"molecular weight") the distinction is not handled properly, but
that's mainly for historical reasons, not because confusing weight
with mass is acceptable.
 
K

Keith Thompson

Phil Carmody said:
So perl can't pass by reference then, and all the chapters about
clever things you can do with references in books about perl by
Wall and Schwartz and uncle Tom Cobbley should be torn out and
filed alongside Schildt?

I did not say that, or anything resembling it. If there's anything
inaccurate in what I *did* say, please point it out.

[...]

The point is that C does not implement pass-by-reference as a
language feature, any more than it implements linked lists as a
language feature. Both features can be implemented or emulated
(choose whichever word you like) in code by explicit use of pointers.

Note that C++ *does* implement pass-by-reference as a language
feature. If you were talking about C++, how would you distinguish
between its language-level pass-by-reference and C-style
pass-via-pointer?

I won't get into Perl here.
 
C

chad

bartc said:



Everyone who is ever likely to use a scale is (or should be) taught
the difference between weight and mass during their schooling, and
they are also taught the appropriate units for each, so they should
understand Newtons just fine.

<OT>
Following in second place is possibly tasing High School AP Science
Teachers that insist on sticking "-age" at the end of a measurement. I
mean, if you call Watts wattage, then why just calling Newtons
Newtonage.
</OT>
 
F

Flash Gordon

Dennis said:
Ok, I kept talking about the immplementation providing _MAX_POWER as a
variable.

It could define it as a keyword if it choose, which would be even more
problematic.
If it's only for its own use, then would it be in a public header?

Because it is used in the macro implementation of a standard function or
standard macro. Real implementations do these kind of things all the
time and they are explicitly allowed to by the standard.

For example, the stddef.h on this machine includes the line...
#define NULL __DARWIN_NULL

So obviously there is a symbol or keyword __DARWIN_NULL defined
somewhere (which I've not bothered to track down, and it could even be
built in to the compiler). However, I'm not aware of any documentation
saying that this identify is intended is intended for you to use (and I
would be very surprised if it was).
Sure it is. The question just asked what was a valid idetifier.
Said nothing about context, so all should be considered.

Um, it is *you* how just introduced a context, i.e. the context in which
any identifier has already been described.

In any case I say again that if you are considering all contexts you
have to consider that in some contexts it is NOT valid, such as an
implementation which has a keyword of __MAX_POWER (which it is allowed to).
That wasn't the question though.

The second paragraph is reasonable context for the question (i.e.
suggesting what it is reasonable to tell a beginner). The first
paragraph is pointing out that if you are considering all contexts
(because none was specified) you need to include those implementations
which choose to make it invalid to use it as an identifier (which they
are allowed to) by causing and translation unit containing that
identifier to fail to translate.
That's not what the question was though.

The question does not exclude implementations where it is "illegal" to
use it as an identifier, so saying it is valid is claiming you can use
it on an implementation where it is guaranteed to cause compilation to fail.
By "doing something" means "defining a symbol with that name", means
that the identifier is valid, else the implementation could not use it
either.

I considered the original question to be implicitly talking about what
is valid in user code, but if you want to include identifiers defined by
the implementation, then the implementation could define it as a
keyword, in which case it is not an identifier defined by the
implementation nor is it something that can be used as an identifier in
user code. An example of such a thing being done is the __try keyword
provided (quite legally) by some implementations.
I answered that below. It reads more into the question than was asked.

I disagree.
be sure that's what you're asking though.
If you simply ask what is a valid identifier, then you leave it open for
identifiers in all contexts - user-defined or implementation defined.

Well, the implementation could define a keyword __MAX_POWER, in which
case it is not an identifier nor can an identifier of that name be
declared or defined. It could even define it as a keyword with similar
semantics to the #error directive, i.e. causing compilation to abort.

However, it is normally considered implicit in questions like "is X
allowed (or valid) in C?" that the question is referring to user code
rather than tricks the implementation might be using internally whilst
not allowing user code to use them. This is especially the case with
questions targetted at beginners.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top