segfault w/ block, but not file scope

C

Chuck F.

Keith said:
.... snip ...

Personally, I learned Pascal before I learned C, so I already
knew about pass-by-value and pass-by-reference. From that
perspective, understanding that passing a pointer is the way to
emulate pass-by-reference in C was very important. Things might
be different for a non-programmer learning C.

On the other hand, I'm not sure that C is a good choice for a
first language. In any case, a programmer should *eventually*
understand the concepts of pass-by-value and pass-by-reference.
And I tend to think that it's at least as important to use C (or
any language) as a vehicle for learning about programming as it
is to learn the details of the language itself.

Fortunately for JRN the use of pass-by-name has virtually
disappeared. In fact fortunately for most of us, IMO.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
A

aegis

Jordan said:
M.B., you clearly don't know what 'pass by reference' means. C doesn't
do it, even with pointers. Whether C++ does it is of no interest here.

Yes it does. time() takes its argument by reference [as do many other
functions in time.h, for historical reasons] You are conflating a
generic concept with a specific feature C++ has that C does not.

No it does not. See "call by value: 3.3.2.2." straight from c89.
Specifically paragraph two. Which states:

"If the expression that denotes the called function has a type that
includes a prototype, the number of arguments shall agree with the
number of parameters. /Each argument shall have a type such that [its
value] may be assigned to an object with the unqualified version of the
type of its corresponding parameter./"

Pass by reference is about passing around actual containers
and not values. The standard is clear here.
There are no two ways about it.
 
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.

How does this make your case? This in no way
suggests that C supports pass by reference.
If you keep on insisting that C supports this concept
then I will have to ask you for a chapter and
verse please.
 
A

aegis

Jordan said:
M.B., you clearly don't know what 'pass by reference' means. C doesn't
do it, even with pointers. Whether C++ does it is of no interest here.

Yes it does. time() takes its argument by reference [as do many other
functions in time.h, for historical reasons] You are conflating a
generic concept with a specific feature C++ has that C does not.

You are the one doing the conflating. C supports pass by value
/only/. See "call by value: 3.3.2.2" from c89.
Specifically paragraph two. Which states:

"If the expression that denotes the called function has a type that
includes a prototype, the number of arguments shall agree with the
number of parameters. /Each argument shall have a type such that [its
value] may be assigned to an object with the unqualified version of the
type of its corresponding parameter./"

Passing by reference has to do with passing around actual
containers or in C's case, objects. 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".
 
J

Jordan Abel

Joe Wright said:
Jordan said:
[...] time() takes its argument by reference [as do many other
functions in time.h, for historical reasons] You are conflating a
generic concept with a specific feature C++ has that C does not.

I may have to look this up because an exact example eludes me right now.

You needn't bother - Jordan is wrong about time() which does not in fact
take its argument by reference. It takes its parameter by value.

It takes a time_t by reference. You are once again refusing to recognize
the existence of the programming technique called "pass by reference" -
if someone started talking about linked lists in here, you wouldn't
object that C doesn't support those, despite the fact that they (unlike
pass by reference) are not used at all by the interface to the standard
library.
 
R

Richard Heathfield

Jordan Abel said:
[...] Jordan is wrong about time() which does not in fact
take its argument by reference. It takes its parameter by value.

It takes a time_t by reference.

No, it doesn't. It takes a time_t * by value.
 
J

Jordan Abel

I know what you're saying, but I think that's an own-foot-shooting way to
say it.

"own-foot-shooting" wording is something that C has its fair share of,
so best not to cast the first stone. See "equivalence of pointers and
arrays" (in, of course, all but three contexts), %f in printf vs scanf
(traceable to the problem of float-to-double argument promotion in
general), the example rand(), etc, etc.

To name an issue that recently came up in here, I think it would have
been better if %s for scanf took "pointer to array of char" rather than
"pointer to char as first member of array".

In particular, the use of the term "object" in C to refer to something
other than what it means to those familiar with other languages is
comparable to this use of "pass by reference" to refer to a programming
technique rather than the language feature it sometimes means instead.
 
J

Jordan Abel

Fortunately for JRN the use of pass-by-name has virtually
disappeared. In fact fortunately for most of us, IMO.

However, see also C Preprocessor macro expansion.
 
J

Jordan Abel

Jordan Abel said:
[...] Jordan is wrong about time() which does not in fact
take its argument by reference. It takes its parameter by value.

It takes a time_t by reference.

No, it doesn't. It takes a time_t * by value.

Which is the means by which it implements a reference to a time_t.
Again, the programming technique (implemented quite easily in C) is
different from the language feature (which C, of course, does not have).
 
M

Mark McIntyre

It is just as amusing as you assertion, backed by no well known authority of
the c language specification, that c does not support pass by reference.

Well, jackass, it doesn't. It supports pass by value, and you may pass
the value of a pointer to emulate pass by reference.
Your continued reference to 'object' during replies proves my assertions

no, it proves he has more patience than most folk.

You're a troll.

*plonk*
Mark McIntyre
 
M

Mark McIntyre

Sorry, Mr. McIntyre, software is a precision art, not hand grenades or
horseshoes. It has a history of development that ought not be forgotten or
convoluted by future misrepresentations simply because the originating concept
is difficult to grasp.

I have no clue what that babble means, but then, Trolls rarely make
sense.
Mark McIntyre
 
J

Jordan Abel

Well, jackass, it doesn't. It supports pass by value, and you may pass
the value of a pointer to emulate pass by reference.

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.
 
C

Chris Torek

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.

The phrase "programming technique" is a little bit slippery (in
much the same sense that an elephant is a little bit large :) ).
C does not have garbage collection either, but you can "emulate"
it by replacing all operations of the form:

p = malloc(nbytes);
...
q = p;
...
q = r;
...
free(q);
...

with:

record_release(p); p = malloc(nbytes); record_ref(p);
...
record_release(q); q = p; record_ref(q);
...
record_release(q); q = r; record_ref(q);
...
record_release(q); free(q); q = NULL; /* for future record_release */

(make sure that p==NULL and q==NULL initially, of course).

If you do this, would you claim that C now "has" garbage collection?

You can emulate by-reference more easily than you can emulate
automatic garbage collection. Does the difficulty of emulation
play a role in deciding whether the language "has" the thing being
emulated?
 
R

Richard Tobin

Jordan Abel said:
That's not "emulating pass by reference", that is passing by reference.

You will find yourself talking at cross-purposes if you take that
approach, since most people don't take "has call-by-reference" to mean
"can achieve the effect of call-by-reference by use of a pointer".

You're well on your way to the Turing tar-pit.

-- Richard
 
K

Keith Thompson

You will find yourself talking at cross-purposes if you take that
approach, since most people don't take "has call-by-reference" to mean
"can achieve the effect of call-by-reference by use of a pointer".

You're well on your way to the Turing tar-pit.

The phrase wasn't "has call-by-reference" (referring to the C
language), it was "is passing by referenece" (referring to the
technique of passing a pointer to an object to allow a function to
modify the object).

C doesn't "have" linked lists, but in a program using the usual
technique involving structures and pointers, the linked lists are real
linked lists.
 
M

M.B

Keith said:
You don't need to write flawless English, especially if it doesn't
happen to be your native language, but avoiding abbreviations like "u"
for "you" and "bcoz" for "because" make it *much* easier to understand
you.


Too many SMS s . I will try
As far as I know it does. Are you saying it doesn't?

Not for me (and i dont know why).
Chuck F. is not a troll. Trust me on this.

I know. Chuck F and others, I apologise
 
J

Jordan Abel

You will find yourself talking at cross-purposes if you take that
approach, since most people don't take "has call-by-reference" to mean
"can achieve the effect of call-by-reference by use of a pointer".

Nobody said "has call-by-reference". In the initial context, the mention
of "pass by reference / pass by value" was perfectly clear. It's only
this subsequent arguing in circles that has muddied the waters.
 
D

Default User

Mark McIntyre wrote:

I have no clue what that babble means, but then, Trolls rarely make
sense.


You're starting to get it. Now, the final enlightenment will be to stop
replying to this cretin.



Brian
 

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

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top