Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #43936 > unrolled thread

pass by address

Started by"Bill Cunningham" <nosapm@nspam.invalid>
First post2014-05-02 16:53 -0400
Last post2014-05-03 21:43 +0000
Articles 11 on this page of 51 — 15 participants

Back to article view | Back to comp.lang.c


Contents

  pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-02 16:53 -0400
    Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-02 17:03 -0400
      Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-02 17:20 -0400
    Re: pass by address Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-05-02 17:58 -0400
      Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-02 18:09 -0400
        Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-02 16:37 -0700
          Re: pass by address gazelle@shell.xmission.com (Kenny McCormack) - 2014-05-02 23:43 +0000
            Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-03 15:58 +0200
              Re: pass by address gazelle@shell.xmission.com (Kenny McCormack) - 2014-05-03 14:08 +0000
                Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-03 10:38 -0700
                  Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-03 21:13 +0200
          Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-03 01:46 -0400
          Re: pass by address "Bill Cunningaham" <nospam@nspam.invalid> - 2014-05-03 11:22 -0400
            Re: pass by address James Kuyper <jameskuyper@verizon.net> - 2014-05-03 12:13 -0400
            Re: pass by address Keith Thompson <kst-u@mib.org> - 2014-05-03 12:34 -0700
              Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-03 22:33 +0200
              Re: pass by address glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-05-03 21:21 +0000
                Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-04 00:08 -0400
                  Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-03 21:52 -0700
                    Re: pass by address Tonton Th <tth@nowhere.invalid> - 2014-05-04 08:44 +0000
                      Re: pass by address Keith Thompson <kst-u@mib.org> - 2014-05-04 01:51 -0700
                        Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-04 15:06 -0400
                          Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-04 15:35 -0700
                            Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-05 12:01 +0200
                              Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-05 11:46 -0700
                            Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-05 14:18 -0400
                              Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-05 11:55 -0700
                                Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-05 15:20 -0400
                                  Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-05 15:23 -0400
                                    Re: pass by address Ken Brody <kenbrody@spamcop.net> - 2014-05-06 11:02 -0400
                                      Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-06 14:46 -0400
                          Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-05 12:00 +0200
                          Re: pass by address Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-05-05 14:50 -0700
                            Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-05 23:13 -0400
                              Re: pass by address "Osmium" <r124c4u102@comcast.net> - 2014-05-05 23:09 -0500
                                Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-06 08:55 -0400
                              Re: pass by address Ken Brody <kenbrody@spamcop.net> - 2014-05-06 11:16 -0400
                                Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-06 18:13 +0200
                        Re: pass by address Kaz Kylheku <kaz@kylheku.com> - 2014-05-04 21:06 +0000
                          Re: pass by address Kaz Kylheku <kaz@kylheku.com> - 2014-05-04 23:50 +0000
                    Re: pass by address Keith Thompson <kst-u@mib.org> - 2014-05-04 12:36 -0700
                    Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-05 14:21 -0400
                  Re: pass by address Keith Thompson <kst-u@mib.org> - 2014-05-04 01:29 -0700
                    Re: pass by address "Bill Cunningham" <nospam@nspam.invalid> - 2014-05-04 15:09 -0400
          Re: pass by address "Bill Cunningaham" <nospam@nspam.invalid> - 2014-05-03 11:32 -0400
    Re: pass by address Barry Schwarz <schwarzb@dqel.com> - 2014-05-02 16:43 -0700
      Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-03 01:54 -0400
        Re: pass by address Richard <rgrdev_@gmail.com> - 2014-05-03 15:59 +0200
      Re: pass by address "Bill Cunningham" <nosapm@nspam.invalid> - 2014-05-03 02:08 -0400
        Re: pass by address "Bill Cunningaham" <nospam@nspam.invalid> - 2014-05-03 11:46 -0400
      Re: pass by address Kaz Kylheku <kaz@kylheku.com> - 2014-05-03 21:43 +0000

Page 3 of 3 — ← Prev page 1 2 [3]


#44008

FromKeith Thompson <kst-u@mib.org>
Date2014-05-04 12:36 -0700
Message-ID<lneh09jpyz.fsf@nuthaus.mib.org>
In reply to#43991
Barry Schwarz <schwarzb@dqel.com> writes:
> On Sun, 4 May 2014 00:08:07 -0400, "Bill Cunningham"
> <nospam@nspam.invalid> wrote:
>>    It wasn't the compiler it was the indent program. It mentioned = &. I 
>>can't seem to remember how to redirect stderr now. And this code works. So I 
>>don't know why people are telling me it doesn't. I think some people are 
>>just playing around with me and lying and trying to confuse me. Well here it 
>>is.
>>
>>#include <stdio.h>
>>
>>int main()
>>{
>>    int a = 15;
>>    int *p;
>>    p = &a;
>>    printf("%p\n", &p);
>
> Undefined behavior #1.
>
>>    printf("%p\n", p);
>
> Undefined behavior #2.
>
>>    printf("%d\n", *p);
>>}
>>
>>The result.
>>
>>0x7fff8a9bb7b0
>>0x7fff8a9bb7bc
>>15
>>
>>And everytime this is run there is a new addresss used.
>
> And this surprises you because?

Are you suggesting that the program's output varies because of the
undefined behavior?  That's theoretically possible, but very unlikely.

"%p" requires an argument of type void*, the above calls should be
written as:

    printf("%p\n", (void*)&p);
    printf("%p\n", (void*)p);

But omitting the cast is unlikely to have any *visible* effect on
almost all existing implementations.

If the output varies from one run to the next, it's just because memory
is allocated differently, perhaps by accident or perhaps because of a
deliberate security measure.

http://en.wikipedia.org/wiki/Address_space_layout_randomization

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#44044

From"Bill Cunningham" <nospam@nspam.invalid>
Date2014-05-05 14:21 -0400
Message-ID<lk8krj$17g$1@dont-email.me>
In reply to#43991
"Barry Schwarz" <schwarzb@dqel.com> wrote in

> And this surprises you because?

    I'm not suprises at all Barry. Why would I be surprised? I just made a 
simple statement. The sun will set today and rise tomorrow.

[toc] | [prev] | [next] | [standalone]


#43995

FromKeith Thompson <kst-u@mib.org>
Date2014-05-04 01:29 -0700
Message-ID<lnvbtmj6aj.fsf@nuthaus.mib.org>
In reply to#43989
"Bill Cunningham" <nospam@nspam.invalid> writes:
[...]
>     It wasn't the compiler it was the indent program. It mentioned = &.

Surprisingly, GNU indent 2.2.11 does produce a warning for
    p=&a;
namely:
   Warning:old style assignment ambiguity in "=&".  Assuming "= &"

Of course you did explicitly say it was the compiler.  And you wouldn't
have seen the warning if you had simply copied the code that Lew
suggsted to you without deleting the whitespace.

> I can't seem to remember how to redirect stderr now.

You can't copy-and-paste an error message?

>                                                      And this code
> works. So I don't know why people are telling me it doesn't.

I don't recall anyone telling you Lew's code wouldn't work.  Here it is,
in its entirety:

  int a = 15;
  int *p;

  p = &a;

  printf("%d\n",*p);
  scanf("%d\n",p);

I see nothing wrong with it (apart from the poor behavior of scanf on
certain forms of bad input, but that's beside the point).

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#44005

From"Bill Cunningham" <nospam@nspam.invalid>
Date2014-05-04 15:09 -0400
Message-ID<lk639s$os$1@dont-email.me>
In reply to#43995
"Keith Thompson" <kst-u@mib.org> wrote in message 
news:lnvbtmj6aj.fsf@nuthaus.mib.org...
> "Bill Cunningham" <nospam@nspam.invalid> writes:
> [...]
>>     It wasn't the compiler it was the indent program. It mentioned = &.
>
> Surprisingly, GNU indent 2.2.11 does produce a warning for
>    p=&a;
> namely:
>   Warning:old style assignment ambiguity in "=&".  Assuming "= &"
>
> Of course you did explicitly say it was the compiler.  And you wouldn't
> have seen the warning if you had simply copied the code that Lew
> suggsted to you without deleting the whitespace.
>
>> I can't seem to remember how to redirect stderr now.
>
> You can't copy-and-paste an error message?

    It's kind of hard to do at the command line. While I'm typing

indent -kr -nut ...//I have to redirect to do it all in one line.

[...]

[toc] | [prev] | [next] | [standalone]


#43967

From"Bill Cunningaham" <nospam@nspam.invalid>
Date2014-05-03 11:32 -0400
Message-ID<lk3272$ja9$1@dont-email.me>
In reply to#43950
"Barry Schwarz" <schwarzb@dqel.com> wrote in message 
news:bfa8m9hgf8af40gkotf6mgv3ke08mpep0d@4ax.com...
> On Fri, 2 May 2014 18:09:20 -0400, "Bill Cunningham"
> <nosapm@nspam.invalid> wrote:
>
>>
>>"Lew Pitcher" <lew.pitcher@digitalfreehold.ca> wrote in message
>>news:NxU8v.443052$1p2.55006@fx13.iad...
>>
>>> Bill, think about this one a bit....
>>>
>>>  int a = 15;
>>>  int *p;
>>>
>>>  p = &a;
>>>
>>>  printf("%d\n",*p);
>>>  scanf("%d\n",p);
>>
>>    That's really simple to interpret. Anyway. You are passing to printf 
>> the
>>value stored at the pointee's address. With the scanf you are passing the
>
> In your terminology, the pointer points to the pointee.  So this is
> the same as saying you pass the value of the pointee.
>
>>pointer's address. Since pointers can only hold addresses. I would say the
>
> No.  With scanf you are passing the value of the pointer, not its
> address.  That value is the address of a, not of p.
>
>>scanf  example is "pass by address" and the printf example is "pass by
>
> You can, and usually do, say whatever you want but the simple fact is
> that this is pass by value.  The value happens to be an address.  I
> don't think anyone has ever said pass by int or pass by double so I
> wonder why you consider this particular type of value worthy of
> special terminology.
>
>>value". Is that right? But with scanf in your example; that's the first 
>>time
>>I've ever seen the /pointer's/ address passed. Usually it's the 
>>/pointee's/
>
> Here you don't see the pointer's address passed, you see the pointer's
> value passed.  But you have seen a pointer's addressed passed just
> within the past week.  Go back and look at your previous messages
> regarding strtol.
>
>>address using the &. But then that second parameter is an elipses and I
>>haven't considered variable argument lists. Way over my head right now
>>anyway.
>
> You might have an easier time understanding things if you didn't keep
> throwing in unrelated issues at the last minute.  Variable argument
> lists have nothing to do with whether you pass an object's value or
> its address to a function.  That decision is based entirely on the
> requirements of the function.

    Ok maybe I better back up and take things from another angle. I will be 
studying this week though.

[toc] | [prev] | [next] | [standalone]


#43952

FromBarry Schwarz <schwarzb@dqel.com>
Date2014-05-02 16:43 -0700
Message-ID<e1b8m9ts8r0etmrn2te17g36k19rsra2hp@4ax.com>
In reply to#43936
On Fri, 2 May 2014 16:53:01 -0400, "Bill Cunningham"
<nosapm@nspam.invalid> wrote:

>    Now there is something new I've never heard of til now from reading a C 
>book called "pass by address". Now am I understanding it right. I will use 
>this example.

Throw the book away.  It is just confusing you.
>
>I think scanf might be like this. The second parameter by wanting a pointer 
>is usually passed the address of the pointee using the ampersand (In know 
>there's an elipsis there). But a value is decalred and initialized. Their is 
>no pointer addresss involved. Is that "pass by address"?

Pass by address means whatever you and the author of the book intend
it to mean.  While it is true that there is no pointer OBJECT in this
code sample, there is a pointer VALUE being passed.  The type of the
expression &n is pointer to int.

>
>    int a=15;
>    scanf("%d\n",&n);
>
>See no pointer address. But a pointee address is passed. The /value/ is 15.

What do you mean by the phrase "no pointer address"?  &n is an address
of type pointer to int.

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#43957

From"Bill Cunningham" <nosapm@nspam.invalid>
Date2014-05-03 01:54 -0400
Message-ID<lk20a0$9bs$1@dont-email.me>
In reply to#43952
"Barry Schwarz" <schwarzb@dqel.com> wrote in message 
news:e1b8m9ts8r0etmrn2te17g36k19rsra2hp@4ax.com...
> On Fri, 2 May 2014 16:53:01 -0400, "Bill Cunningham"
> <nosapm@nspam.invalid> wrote:
>
>>    Now there is something new I've never heard of til now from reading a 
>> C
>>book called "pass by address". Now am I understanding it right. I will use
>>this example.
>
> Throw the book away.  It is just confusing you.
>>
>>I think scanf might be like this. The second parameter by wanting a 
>>pointer
>>is usually passed the address of the pointee using the ampersand (In know
>>there's an elipsis there). But a value is decalred and initialized. Their 
>>is
>>no pointer addresss involved. Is that "pass by address"?
>
> Pass by address means whatever you and the author of the book intend
> it to mean.  While it is true that there is no pointer OBJECT in this
> code sample, there is a pointer VALUE being passed.  The type of the
> expression &n is pointer to int.
>
>>
>>    int a=15;
>>    scanf("%d\n",&n);
>>
>>See no pointer address. But a pointee address is passed. The /value/ is 
>>15.
>
> What do you mean by the phrase "no pointer address"?  &n is an address
> of type pointer to int.

    Right but a *pointee's *address is passed. The a which in memory is an 
int. Barry you are making things more confusing than they need to be. I 
posted this to clear things up.

 int a; //address of type in hold's value of 15 a variable.
int *p; //pointer's address
p=&a; //pointer's address contain's address of location in memory where 
value is stored.

printf("%d",*p); // passed to printf value at address pointed to by p.

Does that make sense? This is the way I'm understanding it.

[toc] | [prev] | [next] | [standalone]


#43963

FromRichard <rgrdev_@gmail.com>
Date2014-05-03 15:59 +0200
Message-ID<8738grhsj6.fsf@gmail.com>
In reply to#43957
"Bill Cunningham" <nosapm@nspam.invalid> writes:

> "Barry Schwarz" <schwarzb@dqel.com> wrote in message 
> news:e1b8m9ts8r0etmrn2te17g36k19rsra2hp@4ax.com...
>> On Fri, 2 May 2014 16:53:01 -0400, "Bill Cunningham"
>> <nosapm@nspam.invalid> wrote:
>>
>>>    Now there is something new I've never heard of til now from reading a 
>>> C
>>>book called "pass by address". Now am I understanding it right. I will use
>>>this example.
>>
>> Throw the book away.  It is just confusing you.
>>>
>>>I think scanf might be like this. The second parameter by wanting a 
>>>pointer
>>>is usually passed the address of the pointee using the ampersand (In know
>>>there's an elipsis there). But a value is decalred and initialized. Their 
>>>is
>>>no pointer addresss involved. Is that "pass by address"?
>>
>> Pass by address means whatever you and the author of the book intend
>> it to mean.  While it is true that there is no pointer OBJECT in this
>> code sample, there is a pointer VALUE being passed.  The type of the
>> expression &n is pointer to int.
>>
>>>
>>>    int a=15;
>>>    scanf("%d\n",&n);
>>>
>>>See no pointer address. But a pointee address is passed. The /value/ is 
>>>15.
>>
>> What do you mean by the phrase "no pointer address"?  &n is an address
>> of type pointer to int.
>
>     Right but a *pointee's *address is passed. The a which in memory is an 
> int. Barry you are making things more confusing than they need to be. I 
> posted this to clear things up.
>
>  int a; //address of type in hold's value of 15 a variable.
> int *p; //pointer's address

LOL! Genius. So wrong it can ONLY be a troll! 


> p=&a; //pointer's address contain's address of location in memory where 
> value is stored.
>
> printf("%d",*p); // passed to printf value at address pointed to by p.
>
> Does that make sense? This is the way I'm understanding it.
>

-- 
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

[toc] | [prev] | [next] | [standalone]


#43958

From"Bill Cunningham" <nosapm@nspam.invalid>
Date2014-05-03 02:08 -0400
Message-ID<lk214i$dc4$1@dont-email.me>
In reply to#43952
"Barry Schwarz" <schwarzb@dqel.com> wrote in message 
news:e1b8m9ts8r0etmrn2te17g36k19rsra2hp@4ax.com...

[snip]
> What do you mean by the phrase "no pointer address"?  &n is an address
> of type pointer to int.

    The best explaination I've seen yet.
http://www.nongnu.org/c-prog-book/online/c620.html


[toc] | [prev] | [next] | [standalone]


#43969

From"Bill Cunningaham" <nospam@nspam.invalid>
Date2014-05-03 11:46 -0400
Message-ID<lk330o$ole$1@dont-email.me>
In reply to#43958
"Bill Cunningham" <nosapm@nspam.invalid> wrote in message 
news:lk214i$dc4$1@dont-email.me...
>    The best explaination I've seen yet.
> http://www.nongnu.org/c-prog-book/online/c620.html
>

    This is a good post above. It shows effort. I'm sure it will be ignored.

[toc] | [prev] | [next] | [standalone]


#43980

FromKaz Kylheku <kaz@kylheku.com>
Date2014-05-03 21:43 +0000
Message-ID<20140503141854.612@kylheku.com>
In reply to#43952
On 2014-05-02, Barry Schwarz <schwarzb@dqel.com> wrote:
> On Fri, 2 May 2014 16:53:01 -0400, "Bill Cunningham"
><nosapm@nspam.invalid> wrote:
>
>>    Now there is something new I've never heard of til now from reading a C
>>book called "pass by address". Now am I understanding it right. I will use
>>this example.
>
> Throw the book away.  It is just confusing you.

Yes; along with his collection of take-out menus, and washing instructions
labels on clothing.

"I think I understand delicate, but why do I have to wash my hands, and
be standing in cold water when doing it?"

[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.c


csiph-web