segfault w/ block, but not file scope

A

aegis

Jordan said:
And uses it extensively in the standard library:

math.h: frexp, modf,
stdio.h: fscanf (and friends), fprintf (and friends, for %n), fgetpos,
fsetpos,
stdlib.h: strtol (and friends),
time.h: mktime, time, asctime, asctime, ctime, gmtime, localtime

Possibly others i've missed from later standards (this was written by
grepping c89 for (.*\*.*) and manually selecting the functions that use
this mechanism.

This is suppose to be suggestive of C supporting
pass by reference? You will have to try harder than that.
Chapter and verse please!
 
J

Joseph Dionne

Jordan said:
That's not "emulating pass by reference", that is passing by reference.
The fact that the language doesn't have special syntax for it doesn't
mean it's suddenly a different programming technique.


Here, here! Just because K&R describes the process of how a function is
called, i.e. copies are placed on the stack before the function call, does not
imply c is only pass by value.

Under the hood, Pascal and c++ do exactly the same technique. However, I will
concede the syntax in Pascal and c++ supports pass by reference, making it
easier for developers to not "think" about what they code.

I guess learning assembler as my first language has endeared me to the c
language and I *might* be hypersensitive.
 
M

M.B

Jordan said:
That's not "emulating pass by reference", that is passing by reference.
The fact that the language doesn't have special syntax for it doesn't
mean it's suddenly a different programming technique.

Ok if your argument is correct,
do you say C has (not emulate) linked lists,trees,....because we can
create them iusing C
In that case C supports object orientation also.
 
J

Jordan Abel

Passing by reference has to do with passing around actual containers
or in C's case, objects.

I disagree.
We don't do that in C. We instead pass the
values stored in objects around to functions. The standard is clear
here and supports absolutely diddly squat in regards to a concept
called "pass by reference".

The language itself supports absolutely squat in regards to another
concept called "linked list", or "binary tree", or any number of other
things, which means absolutely squat to people who use those concepts
anyway in C regardless.
 
J

Jordan Abel

This is suppose to be suggestive of C supporting
pass by reference? You will have to try harder than that.
Chapter and verse please!

You just said the same thing, in response to the same message, three
different times, in three different ways. Did you forget about your two
earlier posts?
 
J

Jordan Abel

Ok if your argument is correct,
do you say C has (not emulate) linked lists,trees,....because we can
create them iusing C
In that case C supports object orientation also.

C neither supports nor does not support it, because it's not a language
feature, it's a programming technique. THE SAME is true for pass by
reference.

"emulate" isn't the proper word. it's something the programmer _can
implement_ in C. Just like a million other things.
 
C

Chris Dollin

Jordan said:
C neither supports nor does not support it, because it's not a language
feature, it's a programming technique.

No; it's a language feature; that's the use for which the term was
created, and the use it still retains. A language has "call by
reference" when a call f(x) can change the value of the variable
x as a result of assignments in f to the formal parameter corresponding
to x.

It is a point of distinction between Pascal (I speak of the non-Delphic
variety) and C (K&R, 89, and 99) that you can do this in Pascal (by
declaring the formal parameter to be `VAR`) and you can't do it in C
(and you can do it in C++).

You can certainly get a similar /effect/ in C. You can use an argument
type of pointer-to-Spoo instead of Spoo, replace all references to the
formal argument spoo by *spoo, and insert the necessary & in all the calls.
The fact that you have to /do/ this, consistently, everywhere, is part
of the reason for saying that C doesn't "support" (I would say "have",
as "support" is such an unnecessarily vulnerable word) call-by-reference.

The term "call-by-reference" is part of a family of terms [1] describing
the ways in which parameters may pass into and out of procedures. That
any of these ways might /also/ be done explicitly by additional code
in the language - as a technique as opposed to a feature - doesn't make
the terms valueless and the distinctions they draw irrelevant.

[1] Call by value, call by result, call by value-result, call by reference,
call by value, call by name. "Pass by" would have been better ...
 
J

Jordan Abel

No; it's a language feature; that's the use for which the term was
created, and the use it still retains. A language has "call by
reference" when a call f(x) can change the value of the variable
x as a result of assignments in f to the formal parameter corresponding
to x.

What does the use for which the term "call by reference" was created
have to do with the original poster's use of the term "pass by
reference"? [which, i might add, was completely clear in context.]
The term "call-by-reference" is part of a family of terms [1] describing
the ways in which parameters may pass into and out of procedures. That
any of these ways might /also/ be done explicitly by additional code
in the language - as a technique as opposed to a feature - doesn't make
the terms valueless and the distinctions they draw irrelevant.

[1] Call by value, call by result, call by value-result, call by reference,
call by value, call by name. "Pass by" would have been better ...

the use "pass by" instead of "call by" distinguishes the programming
technique from the language feature.
 
C

Chris Dollin

Jordan said:
No; it's a language feature; that's the use for which the term was
created, and the use it still retains. A language has "call by
reference" when a call f(x) can change the value of the variable
x as a result of assignments in f to the formal parameter corresponding
to x.

What does the use for which the term "call by reference" was created
have to do with the original poster's use of the term "pass by
reference"? [which, i might add, was completely clear in context.]

Because "pass by reference" means - as far as I am aware - "call by
reference" (and vice versa). "call by reference" is the earlier term,
the one which comes to my fingers; sorry if I've injected confusion
by using one rather than t'other.
The term "call-by-reference" is part of a family of terms [1] describing
the ways in which parameters may pass into and out of procedures. That
any of these ways might /also/ be done explicitly by additional code
in the language - as a technique as opposed to a feature - doesn't make
the terms valueless and the distinctions they draw irrelevant.

[1] Call by value, call by result, call by value-result, call by
[reference,
call by value, call by name. "Pass by" would have been better ...

the use "pass by" instead of "call by" distinguishes the programming
technique from the language feature.

That's interesting distinction, but the only place I ever seen it made
is in your post - have you a (preferably online) reference to update me?
 
D

Dik T. Winter

>
> I disagree.

The distinction between passing by reference and passing by value is
that at the callers end you can not distinguish the two, it is at
the callees end that the two are distinguished. So in Algol 60
(which has proper pass by reference (actually pass by name, but the
distinction is minor) and pass by value), you can not see from the
line:
routine(argument)
whether the argument is passed by reference or by value. Note also
that in some languages (Fortran) pass by reference is indistinguishable
from pass by value-return (i.e. the value of the argument is passed to
the routine and when the routine terminates a new value is assigned to
the argument).

In C pass by references is only performed with array's (but it is actually
simulated by The Rule).
 
C

Chris Dollin

Dik said:
The distinction between passing by reference and passing by value is
that at the callers end you can not distinguish the two, it is at
the callees end that the two are distinguished. So in Algol 60
(which has proper pass by reference (actually pass by name, but the
distinction is minor)

(snip)

Surely not, as Jensen's Device illustrates. (And trying to compile
it.)
 
R

Richard Tobin

(which has proper pass by reference (actually pass by name, but the
distinction is minor) and pass by value)

The distinction is minor when the actual parameter is a variable, but
not when it is an expression. In the latter case you have something
like a closure (traditionally called a "thunk" in this context).

Or was your use of "proper" meant to imply that pass by reference
ought to work like this?

-- Richard
 
M

Michael Wojcik

That's not "emulating pass by reference", that is passing by reference.
The fact that the language doesn't have special syntax for it doesn't
mean it's suddenly a different programming technique.

I'm with Mark, Richard, and Chris on this. Aside from Mr Dionne's
rather confused comments, this thread appears to hang largely on the
question of how strictly one defines the term "pass by reference".
You appear to hold that it covers any "technique" whereby a
"reference" to a variable is passed. I'd call that, at best,
"passing a reference" (where in this context "reference" is an
informal, and not very useful, term for "pointer to an object of the
appropriate type").

I agree with Chris (or what I take to be the main point of one of his
posts in this thread): "pass by reference" is more usefully defined
specifically as a syntactic feature of a language. And C does not
have that syntactic feature.
 
J

Jordan Abel

That's interesting distinction, but the only place I ever seen it made
is in your post - have you a (preferably online) reference to update me?

I coined it just now because I think the programming technique deserves
a name. What would you call the technique used in the list of standard
library functions i named upthread?
 
R

Richard Tobin

I coined it just now because I think the programming technique deserves
a name. What would you call the technique used in the list of standard
library functions i named upthread?

Perhaps it would be clearer to say that you are "passing a reference"
rather than "passing by reference"?

-- Richard
 
J

Jordan Abel

Perhaps it would be clearer to say that you are "passing a reference"
rather than "passing by reference"?

Regardless, I think the original post (which was not mine) was clear to
all involved, and was called out entirely for the sake of nitpicking as
such.
 
K

Keith Thompson

Joseph Dionne said:
Jordan Abel wrote: [...]
That's not "emulating pass by reference", that is passing by
reference.
The fact that the language doesn't have special syntax for it doesn't
mean it's suddenly a different programming technique.


Here, here! Just because K&R describes the process of how a function
is called, i.e. copies are placed on the stack before the function
call, does not imply c is only pass by value.

Does K&R really say that arguments are passed by placing their values
on "the stack"? I'd be a bit surprised by that, since the C standard
doesn't talk about a stack, and a number of real-world implementations
pass most arguments in registers.

If so, are you referring to K&R1 or K&R2, and can you provide a page
or section number?

I don't have my copies of K&R 1&2 handy, though I will later today.
There's no reference to "stack" in the errata at
<http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html>. If it really does
talk about "the stack", perhaps there should be.

Leaving stack questions aside, I'll say for the Nth time that C's
parameter passing is *only* pass by value; pass by reference can be
implemented by the programmer using pointers (and the technique is
used in several places in the standard library).
 
K

Keith Thompson

Perhaps it would be clearer to say that you are "passing a reference"
rather than "passing by reference"?

No, because too many readers will assume "reference" refers to a
certain C++ language feature that C lacks.
 
K

Keith Thompson

I'm with Mark, Richard, and Chris on this. Aside from Mr Dionne's
rather confused comments, this thread appears to hang largely on the
question of how strictly one defines the term "pass by reference".
You appear to hold that it covers any "technique" whereby a
"reference" to a variable is passed. I'd call that, at best,
"passing a reference" (where in this context "reference" is an
informal, and not very useful, term for "pointer to an object of the
appropriate type").

I agree with Chris (or what I take to be the main point of one of his
posts in this thread): "pass by reference" is more usefully defined
specifically as a syntactic feature of a language. And C does not
have that syntactic feature.

Ok, I think we're all in agreement about what the built-in features of
the C language are (pass-by-value, no pass-by-reference), and about
the usefulness of a certain technique that can be implemented using
lower-level language features (passing a pointer so the called
function can modify the object that it points to, or just to avoid
unnecessarily copying the entire object). (All of us with the
possible exception of Mr. Dionne; he has so far failed to make clear
just what he thinks.)

Now we're down to a question of terminology. The standard doesn't
provide a term for this technique, so we have to fall back to general
programming jargon or plain English.

Someone who programs both in C and in other languages needs to
understand that passing a pointer is the way to implement what can be
done with a built-in feature in certain other languages. Someone who
programs only in C should still have some understanding of programming
in general, particularly of the very common programming technique of
passing an argument to a function in a way that doesn't copy the value
of the argument and that allows the function to modify a specified
object. We need to understand how this technique is implemented in
terms of C pointers being passed by value (copied) into the function,
but it's not useful to ignore the existence of the technique and talk
only about the lower-level constructs used to implement it, any more
than it would be useful to talk only about pointers and structures in
a program that implements a linked list.

Here are a couple of questions for those of you who insist that the
term "pass by reference" should apply only to a built-in language
feature:

What do you call the corresponding programming technique? (Ideally,
I'd like to see a pity and language-independent term, just as we use
the term "linked list" regardless of the implementation language.)

If some other language, say C+++ (sic), had built-in support for
linked lists, would you insist on not using the term "linked list" in
the context of a C program?
 
A

aegis

Jordan said:
You just said the same thing, in response to the same message, three
different times, in three different ways. Did you forget about your two
earlier posts?

I posted this the other day but google delayed it by a substantial
amount of time. Being that the post did not appear immediately
(when it usually does), I figured the issue was something else and
hence for my reposting.
 

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,007
Messages
2,570,266
Members
46,863
Latest member
montyonthebonty

Latest Threads

Top