Connecting Tech Pros Worldwide Forums | Help | Site Map

Trying to understand pointers for function paramaters

Richard Hengeveld
Guest
 
Posts: n/a
#1: Nov 14 '05
Hi all,

I'm trying to understand how pointers for function parameters work. As I
understand it, if you got a function like:

void f(int *i)
{
*i = 0;
}

int main()
{
int a;
f(&a);
return 0;
}

It does what you want (namely altering the value of a).
I find this illogical. As far as I can understand, the address of "a" is
passed, and "*i" is set with this address not "i", as it should be in my
understanding.
What am I missing?
TIA

P.S.
I've really searched for this in the groups faq and elsewhere before I
posted.



Mark A. Odell
Guest
 
Posts: n/a
#2: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> wrote in
news:415ae427$0$76520$b83b6cc0@news.wanadoo.nl:
[color=blue]
> Hi all,
>
> I'm trying to understand how pointers for function parameters work. As I
> understand it, if you got a function like:
>
> void f(int *i)
> {
> *i = 0;
> }
>
> int main()
> {
> int a;
> f(&a);
> return 0;
> }[/color]

Assume that 'a' exist at memory location 0x1000'0000. Now assume 'i' is
located at 0x1000'0004.

Before calling f():
-------------------
C name Mem. Addr. Contents (value located there)
------ ------------ ------------------------------
a 0x1000'0000: ???
i 0x1000'0004: ???

In function f() after the assignment to *i:
-------------------------------------------

C name Mem. Addr. Contents (value located there)
------ ------------ ------------------------------
a 0x1000'0000: 0
i 0x1000'0004: 0x1000'0000

so 'i' is a pointer that contains the value of the address of 'a'. Thus
weh you dereference 'i' via *i you now point to memory location
0x1000'0000. So if you modify what is as 0x1000'0000 then the value of 'a'
will be modified.

Simple, logical.

--
- Mark ->
--
Keith Thompson
Guest
 
Posts: n/a
#3: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> writes:[color=blue]
> Hi all,
>
> I'm trying to understand how pointers for function parameters work. As I
> understand it, if you got a function like:
>
> void f(int *i)
> {
> *i = 0;
> }
>
> int main()
> {
> int a;
> f(&a);
> return 0;
> }
>
> It does what you want (namely altering the value of a).
> I find this illogical. As far as I can understand, the address of "a" is
> passed, and "*i" is set with this address not "i", as it should be in my
> understanding.
> What am I missing?[/color]

Yes, you're passing the address of "a" to the function "f".

Incidentally, "i" is a poor name for the parameter. "i" is commonly
used as a name for an int variable; the parameter is a pointer to int.
It's perfectly legal, but potentially confusing.

In the assignment

*i = 0;

"i" is a pointer, and "*i" is an int object. You're assigning the
value 0 to an int object. Which int object? The one i points to,
which happens to be "a".

If you had written

i = 0;

you'd be assigning a value to "i", which is a pointer object; the
value being assigned would be a null pointer.

It might be clearer if you change the names:

void f(int *ptr_param)
{
*ptr_param = 0;
}

int main(void)
{
int int_object;
f(&int_object);
return 0;
}

(In a real program, of course, variables should generally have names
that reflect what they're used for; for this toy example, it's more
important to show their types.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
E. Robert Tisdale
Guest
 
Posts: n/a
#4: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:
[color=blue]
>
>
> I'm trying to understand how pointers for function parameters work.
> As I understand it, if you got a function like:
>
> void f(int* p) {
> *p = 0;
> }
>
> int main(int argc, char* argv[]) {
> int a;
> f(&a);
> return 0;
> }
>
> It does what you want (namely altering the value of a).
> I find this illogical. As far as I can understand,
> the address of "a" is passed,
> and "*p" is set with this address not "p"
> as it should be in my understanding.[/color]

Probably what is confusing you is the *formal* argument

int* p

This tells you that p is a pointer to an object of type int.
the statement

p = 0;

would assign the address value 0 to p.
The expression

*p

is a *reference* to (another name for) a
so writing

*p = 0;

is the same thing as writing

a = 0;

Richard Hengeveld
Guest
 
Posts: n/a
#5: Nov 14 '05

re: Trying to understand pointers for function paramaters



"E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> wrote in message
news:cjf5pb$fg5$1@nntp1.jpl.nasa.gov...[color=blue]
> Richard Hengeveld wrote:
>[color=green]
> >
> >
> > I'm trying to understand how pointers for function parameters work.
> > As I understand it, if you got a function like:
> >
> > void f(int* p) {
> > *p = 0;
> > }
> >
> > int main(int argc, char* argv[]) {
> > int a;
> > f(&a);
> > return 0;
> > }
> >
> > It does what you want (namely altering the value of a).
> > I find this illogical. As far as I can understand,
> > the address of "a" is passed,
> > and "*p" is set with this address not "p"
> > as it should be in my understanding.[/color]
>
> Probably what is confusing you is the *formal* argument
>
> int* p[/color]

Thanks for replying.
Yes, that is exactly what is confusing me.
I understand you set a pointer (if you're not passing to functions) by:

int a, *p;
p = &a;

and not:

p* = &a

Wouldn't it be more logical if it was something like:

void f(int i) {
int *p
p = i;
p* = 0;
}

int main(int argc, char* argv[]) {
int a;
f(&a);
return 0;
}

?









Keith Thompson
Guest
 
Posts: n/a
#6: Nov 14 '05

re: Trying to understand pointers for function paramaters


"E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:[color=blue]
> Richard Hengeveld wrote:
>[color=green]
>>
>>
>> I'm trying to understand how pointers for function parameters work.
>> As I understand it, if you got a function like:
>>
>> void f(int* p) {
>> *p = 0;
>> }
>>
>> int main(int argc, char* argv[]) {
>> int a;
>> f(&a);
>> return 0;
>> }
>>
>> It does what you want (namely altering the value of a).
>> I find this illogical. As far as I can understand,
>> the address of "a" is passed,
>> and "*p" is set with this address not "p"
>> as it should be in my understanding.[/color][/color]

Damn it, Tisdale, that's not what he wrote. Here's what Richard
Hengeveld *actually* wrote in the article to which you replied:

] I'm trying to understand how pointers for function parameters work. As I
] understand it, if you got a function like:
]
] void f(int *i)
] {
] *i = 0;
] }
]
] int main()
] {
] int a;
] f(&a);
] return 0;
] }
]
] It does what you want (namely altering the value of a).
] I find this illogical. As far as I can understand, the address of "a" is
] passed, and "*i" is set with this address not "i", as it should be in my
] understanding.

By prefixing the material with "> ", you're telling us that you're
quoting what the previous poster wrote; by preceding it with "Richard
Hengeveld wrote:", you're saying so explicitly. In fact, you're
showing us your version of what you think he should have written.
You've quietly changed the layout of his code (I like his better),
changed the name of the parameter from "i" to "p", and added
gratuitous argc and argv parameters to main.

Now if you had presented your modified version as an improvement of
Richard Hengeveld's code (which is what I did in my response), that
would have been ok. If you had mentioned that you were paraphrasing
what he posted rather than quoting it exactly, that would have been
acceptable as well. You could even have told us why you think your
modified version is an improvement. (In some ways it is, but that's
beside the point.)

You've done this before, and you've been called on it. I have no
realistic expectation that you're going to change your ways this time
either. I'm posting this mostly as a warning to other readers.

If E. Robert Tisdale claims that someone else has written something in
a previous article, don't believe it unless you've verified it by
reading the actual article that he claims to be quoting. Trust him at
your own risk.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Default User
Guest
 
Posts: n/a
#7: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:

[color=blue]
> Wouldn't it be more logical if it was something like:
>
> void f(int i) {
> int *p
> p = i;
> p* = 0;[/color]


How would it be more logical to assign an integer to a
pointer-to-integer? What problem are you trying to solve?




Brian Rodenborn
Richard Hengeveld
Guest
 
Posts: n/a
#8: Nov 14 '05

re: Trying to understand pointers for function paramaters



"Default User" <first.last@boeing.com.invalid> wrote in message
news:I4tpCx.H6K@news.boeing.com...[color=blue]
> Richard Hengeveld wrote:
>
>[color=green]
> > Wouldn't it be more logical if it was something like:
> >
> > void f(int i) {
> > int *p
> > p = i;
> > p* = 0;[/color]
>
>
> How would it be more logical to assign an integer to a
> pointer-to-integer? What problem are you trying to solve?[/color]

I'm not trying to solve a problem. I'm just trying to understand C.
In a function without pointer arguments, the argument(s) of that function
are set by value passing:

f(int i)
{
printf("%d", i);
}

int main()
{
int i;
f(i);
return 0;
}

I just don't understand why this is (a little bit) different with pointer
arguments.


E. Robert Tisdale
Guest
 
Posts: n/a
#9: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:
[color=blue]
> I understand you set a pointer (if you're not passing to functions) by:
>
> int a, *p;
> p = &a;
>
> and not:
>
> p* = &a
>
> Wouldn't it be more logical if it was something like:
>
> void f(int i) {
> int *p
> p = i;
> p* = 0;
> }
>
> int main(int argc, char* argv[]) {
> int a;
> f(&a);
> return 0;
> }
>
> ?[/color]

I don't know.
I don't know why K&R chose these semantics
and not the semantics that you suggest.
suppose that you wanted to define a second pointer
to the same object. Would you write

int *p, *q;
p = i;
q = i;

And would you expect (p == q) to be true?
Keith Thompson
Guest
 
Posts: n/a
#10: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> writes:
[...][color=blue]
> Thanks for replying.
> Yes, that is exactly what is confusing me.
> I understand you set a pointer (if you're not passing to functions) by:
>
> int a, *p;
> p = &a;[/color]

Right, this sets p to contain the address of a (or, equivalently,
causes p to point to a).
[color=blue]
> and not:
>
> p* = &a[/color]

The unary '*' operator is prefix, not postfix. You could argue that
it would be easier if it were postfix, but that's not how the language
defines it.

If you meant
*p = &a;
that wouldn't make sense. Since p is a pointer to int, *p is an int,
but &a (address of a) is a pointer to int. The types don't match.

In an assignment, the left hand side has to be an expression (e.g., a
name) that refers to an object of some type, and the right hand side
has to be an expression of that same type (not necessarily an object).
(That's not quite true (there are implicit conversions in some cases),
but it's a good enough first approximation.)

So given:
int a;
int *p;
we can have
a = 42; /* the name "a" refers to an object of type int,
"42" is an expression of type int */
p = &a; /* the name "p" refers to an object of type pointer-to-int,
"&a" is an expression of type pointer-to-int */
*p = 2+2; /* the name "*p" refers to an object of type int
(the object happens to be "a"), and "2+2" is an expression
of type int */
[color=blue]
> Wouldn't it be more logical if it was something like:
>
> void f(int i) {
> int *p
> p = i;[/color]

No, p refers to an object of type pointer-to-int, but i is an expression
of type int. The types don't match. You can legally say "p = &i;".
[color=blue]
> p* = 0;[/color]

p* is a syntax error. *p = 0; is legal, since *p refers to an object
of type int (assuming p has been initialized properly), and 0 is an
expression of type int.
[color=blue]
> }
>
> int main(int argc, char* argv[]) {
> int a;
> f(&a);[/color]

The function f() expects an argument of type int; you're giving it an
argument of type pointer-to-int. Function argument types have to
match, just as the types in an assignment have to match.
[color=blue]
> return 0;
> }[/color]

If you want the function f() to be able to modify an int object that
you pass to it, you have to pass the object's address, and f() has to
take an argument of type pointer-to-int. If f() takes an argument of
type int, it just gets a copy of the value of whatever you pass to it;
f() can do whatever it likes with its own copy, but that won't affect
the original object.

If f() is defined as:

void f(int i) { ... whatever ... }

then this:

int x;
f(x);

can't change the value of x, any more than this:

f(42);

can change the value of 42.

Some languages do have ways of specifying that an argument is passed
in a way that allows the function to modify the original object
(Pascal has VAR parameters, Ada as "in out" and "out" parameters, C++
has reference parameters). C doesn't have such a mechanism.

If you want to argue that C could be improved, there are several
things I can say in response:

1. You're right. C's declaration syntax in particular causes no end
of headaches, especially to novices.

2. It's not going to change. Any significant change would break
existing code. That's just not going to happen. If you want a
language with better syntax than C (and that's a subjective
judgement), you'll just have to use a language other than C.

3. If you're interested in C, you should probably learn the language
as it is before you start worrying about how it could be better. K&R2
(Kernighan & Ritchie's _The C Programming Language_, Second Edition)
is one of the best tutorials; buy or borrow a copy and read it.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Default User
Guest
 
Posts: n/a
#11: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:
[color=blue]
>
> "Default User" <first.last@boeing.com.invalid> wrote in message
> news:I4tpCx.H6K@news.boeing.com...[color=green]
> > Richard Hengeveld wrote:
> >
> >[color=darkred]
> > > Wouldn't it be more logical if it was something like:
> > >
> > > void f(int i) {
> > > int *p
> > > p = i;
> > > p* = 0;[/color]
> >
> >
> > How would it be more logical to assign an integer to a
> > pointer-to-integer? What problem are you trying to solve?[/color]
>
> I'm not trying to solve a problem. I'm just trying to understand C.
> In a function without pointer arguments, the argument(s) of that
> function are set by value passing:
>
> f(int i)
> {
> printf("%d", i);
> }
>
> int main()
> {
> int i;
> f(i);
> return 0;
> }
>
> I just don't understand why this is (a little bit) different with
> pointer arguments.[/color]

It's not different. What makes you think it is? In both cases,
something is passed by value (that means a copy of it was made) and
assigned to a local variable, the parameter.

It just so happens that in one case it was a integer, and the other it
was a pointer-to-integer. In the second case, a copy of the address was
made and passed to the function. It's still the same address that was
created through the use of the & operator in main().

You don't appear to understand how pointers work. This is fundamental
to the use of the C language. Get a good book and read it. Otherwise,
you are wasting your time and ours.




Brian Rodenborn
pete
Guest
 
Posts: n/a
#12: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:
[color=blue]
> As far as I can understand, the address of "a" is
> passed, and "*i" is set with this address not "i",
> as it should be in my understanding.[/color]

After
int *i = &a
you have
i == &a
not
*i == &a

--
pete
Pedro Graca
Guest
 
Posts: n/a
#13: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:[color=blue]
>
> "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> wrote in message
> news:cjf5pb$fg5$1@nntp1.jpl.nasa.gov...[color=green]
>>
>> Probably what is confusing you is the *formal* argument
>>
>> int* p[/color]
>
> Thanks for replying.
> Yes, that is exactly what is confusing me.[/color]


[newbie answer -- maybe this helps]


int i, *p; // declare an int and a pointer to int
void f(int *p); // declare a function taking a pointer to int parameter

I think you'd understand that function better if you'd write it as

void g(int* p); // make 'int*' stand out



typedef int *pointer_to_int;
typedef int* pointer_to_int;

These two typedefs are absolutely equal. Which one do you prefer?

void h(pointer_to_int p);

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
CBFalconer
Guest
 
Posts: n/a
#14: Nov 14 '05

re: Trying to understand pointers for function paramaters


Keith Thompson wrote:[color=blue]
>[/color]
.... snip ...[color=blue]
>
> Incidentally, "i" is a poor name for the parameter. "i" is
> commonly used as a name for an int variable; the parameter is a
> pointer to int. It's perfectly legal, but potentially confusing.
>
> In the assignment
>
> *i = 0;
>
> "i" is a pointer, and "*i" is an int object. You're assigning the
> value 0 to an int object. Which int object? The one i points to,
> which happens to be "a".
>
> If you had written
>
> i = 0;
>
> you'd be assigning a value to "i", which is a pointer object; the
> value being assigned would be a null pointer.
>
> It might be clearer if you change the names:
>
> void f(int *ptr_param)
> {
> *ptr_param = 0;
> }
>
> int main(void)
> {
> int int_object;
> f(&int_object);
> return 0;
> }
>
> (In a real program, of course, variables should generally have names
> that reflect what they're used for; for this toy example, it's more
> important to show their types.)[/color]

While I abhor Hungarian notation, I do like to append either p or
ptr to the names of pointer variables.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

CBFalconer
Guest
 
Posts: n/a
#15: Nov 14 '05

re: Trying to understand pointers for function paramaters


Keith Thompson wrote:[color=blue]
> "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
>[/color]
.... snip mangled quote ...[color=blue]
>
> Damn it, Tisdale, that's not what he wrote. Here's what Richard
> Hengeveld *actually* wrote in the article to which you replied:
>[/color]
.... snip details ...[color=blue]
>
> You've done this before, and you've been called on it. I have no
> realistic expectation that you're going to change your ways this
> time either. I'm posting this mostly as a warning to other readers.
>
> If E. Robert Tisdale claims that someone else has written something
> in a previous article, don't believe it unless you've verified it
> by reading the actual article that he claims to be quoting. Trust
> him at your own risk.[/color]

And just when I thought Trollsdale was showing signs of
reformation. He seems to be a dedicated recidivist. Can we apply
the 'three strikes' law somehow?

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Barry Schwarz
Guest
 
Posts: n/a
#16: Nov 14 '05

re: Trying to understand pointers for function paramaters


On Wed, 29 Sep 2004 23:09:10 +0200, "Richard Hengeveld"
<richardhengeveld@hotmail.com> wrote:
[color=blue][color=green]
>> Probably what is confusing you is the *formal* argument
>>
>> int* p[/color]
>
>Thanks for replying.
>Yes, that is exactly what is confusing me.
> I understand you set a pointer (if you're not passing to functions) by:
>
>int a, *p;
>p = &a;
>
>and not:
>
>p* = &a
>
>Wouldn't it be more logical if it was something like:
>
> void f(int i) {
> int *p
> p = i;[/color]

I assume you meant p=&i here.
[color=blue]
> p* = 0;[/color]

I assume you meant *p=0 here. This will set i to 0 but I is local to
f. When you return, i ceases to exist. Consequently, the argument in
the calling function is never updated and defeats the purpose.
[color=blue]
> }
>
> int main(int argc, char* argv[]) {
> int a;
> f(&a);[/color]

With f as defined above, this obviously causes a diagnostic since f is
expecting an int but you are passing an int*.

Going back to your original post which defined f as expecting an int*,
when you call f with this argument, three significant things happen:

i is created as an automatic variable local to f.
i is initialized with the address of a (which is a local variable
local to main.
Control is transferred to f.

Look back at your code at the top of this post and notice how similar
the first two are to what you wrote when not calling a function.
[color=blue]
> return 0;
> }[/color]

The concepts to understand are

In a definition, *i defines i as a pointer.

After the definition, i refers to the pointer itself and not the
object being pointed to, if any.

Once the pointer has been initialized, coding *i dereferences the
pointer and evaluates to the object being pointed to.

A function call causes all the parameters of the function to be
initialized with the corresponding arguments used in the calling
statement. (So f(&a) has a very similar effect to p=&a.)


<<Remove the del for email>>
Flash Gordon
Guest
 
Posts: n/a
#17: Nov 14 '05

re: Trying to understand pointers for function paramaters


On Thu, 30 Sep 2004 04:13:38 GMT
CBFalconer <cbfalconer@yahoo.com> wrote:
[color=blue]
> Keith Thompson wrote:[color=green]
> > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:[/color][/color]

<snip>
[color=blue][color=green]
> > If E. Robert Tisdale claims that someone else has written something
> > in a previous article, don't believe it unless you've verified it
> > by reading the actual article that he claims to be quoting. Trust
> > him at your own risk.[/color]
>
> And just when I thought Trollsdale was showing signs of
> reformation. He seems to be a dedicated recidivist. Can we apply
> the 'three strikes' law somehow?[/color]

You mean if any of us meet him we get to strike him three times? :-)
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Mark A. Odell
Guest
 
Posts: n/a
#18: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> wrote in
news:415b34db$0$76531$b83b6cc0@news.wanadoo.nl:
[color=blue][color=green]
>> How would it be more logical to assign an integer to a
>> pointer-to-integer? What problem are you trying to solve?[/color]
>
> I'm not trying to solve a problem. I'm just trying to understand C.
> In a function without pointer arguments, the argument(s) of that
> function are set by value passing:[/color]

Correct. In this case the called function gets a "copy" of the value to
play with and the caller can be sure that the callee won't modify the
original value in 'i'. This is nice when you want to preserve your value
but have some function create a new value based on your value, e.g.

#include <stdio.h>

static int plusTwo(int copyOfVal)
{
/* Modify copy by adding two to demonstrate
** that the caller's 'val' is not modified.
*/
copyOfVal += 2;

return copyOfVal;
}

static int timesTenModify(int *pVal)
{
int failure = 0;

if (pVal) *pVal *= 10;
else failure = !0;

return failure;
}

int main(void)
{
int failure;
int val = 10;
int valPlusTwo = plusTwo(val);

/* As the caller, I retain my original value of 'val'
** whilst having a worker function calculate 'val' + 2
** for me which I store in 'valPlusTwo'. In this situation
** I do not wish my 'val' to be modified.
*/
printf("My val is %d, and +2 is %d\n", val, valPlusTwo);

/* In this case, I wish to modify 'val' and do not need
** to retain its original value of 10 so I call
** timesTenModify() with a pointer to my 'val' object
** so it can modify 'val' directly.
*/
failure = timesTenModify(&val);
if (failure) printf("Trouble with timesTenModify() call\n");
else printf("My val is now %d\n", val);

return 0;
}
[color=blue]
> I just don't understand why this is (a little bit) different with
> pointer arguments.[/color]

Hopefully this simple example will help.

--
- Mark ->
--
Christopher Benson-Manica
Guest
 
Posts: n/a
#19: Nov 14 '05

re: Trying to understand pointers for function paramaters


CBFalconer <cbfalconer@yahoo.com> spoke thus:
[color=blue]
> And just when I thought Trollsdale was showing signs of
> reformation. He seems to be a dedicated recidivist. Can we apply
> the 'three strikes' law somehow?[/color]

Perhaps there could be a section of the FAQ dedicated to identifying
posters to plonk?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica
Guest
 
Posts: n/a
#20: Nov 14 '05

re: Trying to understand pointers for function paramaters


Pedro Graca <hexkid@hotpop.com> spoke thus:
[color=blue]
> void g(int* p); // make 'int*' stand out[/color]

That's actually misleading - it makes "int*" appear to be a type,
which it is not.
[color=blue]
> typedef int *pointer_to_int;
> typedef int* pointer_to_int;[/color]
[color=blue]
> These two typedefs are absolutely equal. Which one do you prefer?[/color]

Neither, for real code.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
John Bode
Guest
 
Posts: n/a
#21: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> wrote in message news:<415ae427$0$76520$b83b6cc0@news.wanadoo.nl>.. .[color=blue]
> Hi all,
>
> I'm trying to understand how pointers for function parameters work. As I
> understand it, if you got a function like:
>
> void f(int *i)
> {
> *i = 0;
> }
>
> int main()
> {
> int a;
> f(&a);
> return 0;
> }
>
> It does what you want (namely altering the value of a).
> I find this illogical. As far as I can understand, the address of "a" is
> passed, and "*i" is set with this address not "i", as it should be in my
> understanding.
> What am I missing?[/color]

I think you're getting hung up with declarator syntax as much as
anything else, and that you're looking at the formal parameter
declaration as an actual dereference operation, which is why you're
confused.

C declaration statements follow a "declaration mimics use" paradigm.
When you dereference the pointer to get the value it's pointing to,
you use the expression "*i". The idea is that the declaration of "i"
(a pointer) should closely mirror how it's actually used in the code;
therefore, the declaration looks like this:

int *i

The int-ness of i is specified in the type specifier "int"; the
pointer-ness of i is specified in the declarator "*i". This statement
introduces the symbol "i" as having type pointer-to-int (although the
declaration reads as pointer-to-type-int).

When you pass your value (&a, type pointer-to-int) to this function,
it is written to the formal parameter "i" (type pointer-to-int), *not*
to the expression "*i" (type int).

Hope that helps.
[color=blue]
> TIA
>
> P.S.
> I've really searched for this in the groups faq and elsewhere before I
> posted.[/color]
CBFalconer
Guest
 
Posts: n/a
#22: Nov 14 '05

re: Trying to understand pointers for function paramaters


Christopher Benson-Manica wrote:[color=blue]
> CBFalconer <cbfalconer@yahoo.com> spoke thus:
>[color=green]
>> And just when I thought Trollsdale was showing signs of
>> reformation. He seems to be a dedicated recidivist. Can we
>> apply the 'three strikes' law somehow?[/color]
>
> Perhaps there could be a section of the FAQ dedicated to
> identifying posters to plonk?[/color]

Too dynamic. The best I can do is publish my own c.l.c plonk
list. Trollsdale isn't on it because he requires watching else
his alteration tricks will go unnoticed. The FAQ plonks (Answers,
FAQ list) are because I have a copy and don't need any more, and
they are big.

c:\netscape\users\cbf\news\host-netnews.att.net>grep condition=
comp.lang.c.dat
condition=" OR (subject,contains,comp.lang.c Answers)"
condition=" OR (subject,contains,My china ex. girlfriend)"
condition=" OR (from,contains,Kenny McCormack)"
condition=" OR (subject,contains,comp.lang.c FAQ list)"
condition=" OR (from,contains,RoSsIaCrIiLoIA)"
condition=" OR (from,contains,lxrocks)"
condition=" OR (from,contains,Generic Usenet Account)"
condition=" OR (from,contains,SM Ryan)"
condition=" OR (from,contains,Skybuck Flying)"
condition=" OR (subject,contains,C++ wins over C)"
condition=" OR (subject,contains,What is an object)"

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Stephen Sprunk
Guest
 
Posts: n/a
#23: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Richard Hengeveld" <richardhengeveld@hotmail.com> wrote in message
news:415b249d$0$76511$b83b6cc0@news.wanadoo.nl...[color=blue]
> Thanks for replying.
> Yes, that is exactly what is confusing me.
> I understand you set a pointer (if you're not passing to functions) by:
>
> int a, *p;
> p = &a;
>
> and not:
>
> p* = &a[/color]

This is a syntax error; I assume you meant:

*p = &a;

This is a type mismatch; you're trying to assign an address (a) to an
integer (*p) without a cast. Now, if you did:

p = &a;

This is correct. Then you can do:

*p = 1;

And then you will find that a==1. This is no different than doing:

*(&a) = 1;

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

Richard Hengeveld
Guest
 
Posts: n/a
#24: Nov 14 '05

re: Trying to understand pointers for function paramaters


Thanks all for helping me out and being patiant with me.
To be clear, I was not trying to attack c logics or concepts. I was just
trying to learn c. Thanks again.
Richard


Richard Hengeveld
Guest
 
Posts: n/a
#25: Nov 14 '05

re: Trying to understand pointers for function paramaters


Thanks all for helping me out and being patiant with me.
To be clear, I was not trying to attack C logics or concepts. Just trying to
learn C. Thanks again


Mabden
Guest
 
Posts: n/a
#26: Nov 14 '05

re: Trying to understand pointers for function paramaters


"CBFalconer" <cbfalconer@yahoo.com> wrote in message
news:415B8170.4891BC87@yahoo.com...[color=blue]
> Keith Thompson wrote:[color=green]
> > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
> >[/color]
> ... snip mangled quote ...[color=green]
> >
> > Damn it, Tisdale, that's not what he wrote. Here's what Richard
> > Hengeveld *actually* wrote in the article to which you replied:
> >[/color]
> ... snip details ...[color=green]
> >
> > You've done this before, and you've been called on it. I have no
> > realistic expectation that you're going to change your ways this
> > time either. I'm posting this mostly as a warning to other readers.
> >
> > If E. Robert Tisdale claims that someone else has written something
> > in a previous article, don't believe it unless you've verified it
> > by reading the actual article that he claims to be quoting. Trust
> > him at your own risk.[/color]
>
> And just when I thought Trollsdale was showing signs of
> reformation. He seems to be a dedicated recidivist. Can we apply
> the 'three strikes' law somehow?
>[/color]
Shut up! It was the same function with a variable changed.

Where's your input? What is your content?

Nothing!

Fuck off!

--
Mabden


Mabden
Guest
 
Posts: n/a
#27: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
news:7c3t22xsv9.ln2@brenda.flash-gordon.me.uk...[color=blue]
> On Thu, 30 Sep 2004 04:13:38 GMT
> CBFalconer <cbfalconer@yahoo.com> wrote:
>[color=green]
> > Keith Thompson wrote:[color=darkred]
> > > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:[/color][/color]
>
> <snip>
>[color=green][color=darkred]
> > > If E. Robert Tisdale claims that someone else has written[/color][/color][/color]
something[color=blue][color=green][color=darkred]
> > > in a previous article, don't believe it unless you've verified it
> > > by reading the actual article that he claims to be quoting. Trust
> > > him at your own risk.[/color]
> >
> > And just when I thought Trollsdale was showing signs of
> > reformation. He seems to be a dedicated recidivist. Can we apply
> > the 'three strikes' law somehow?[/color]
>
> You mean if any of us meet him we get to strike him three times? :-)[/color]

Shut up!


Keith Thompson
Guest
 
Posts: n/a
#28: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> writes:[color=blue]
> "CBFalconer" <cbfalconer@yahoo.com> wrote in message
> news:415B8170.4891BC87@yahoo.com...[color=green]
>> Keith Thompson wrote:[color=darkred]
>> > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
>> >[/color]
>> ... snip mangled quote ...[color=darkred]
>> >
>> > Damn it, Tisdale, that's not what he wrote. Here's what Richard
>> > Hengeveld *actually* wrote in the article to which you replied:
>> >[/color]
>> ... snip details ...[color=darkred]
>> >
>> > You've done this before, and you've been called on it. I have no
>> > realistic expectation that you're going to change your ways this
>> > time either. I'm posting this mostly as a warning to other readers.
>> >
>> > If E. Robert Tisdale claims that someone else has written something
>> > in a previous article, don't believe it unless you've verified it
>> > by reading the actual article that he claims to be quoting. Trust
>> > him at your own risk.[/color]
>>
>> And just when I thought Trollsdale was showing signs of
>> reformation. He seems to be a dedicated recidivist. Can we apply
>> the 'three strikes' law somehow?
>>[/color]
> Shut up! It was the same function with a variable changed.
>
> Where's your input? What is your content?
>
> Nothing!
>
> Fuck off![/color]

Mabden, whoever you are, I am sick and tired of your insults. You've
sometimes shown signs of being worth talking to, but if I had a
killfile, you would have been in it several times over by now.
Tisdale deliberately forged a quotation, making it appear that the
previous poster had written something he didn't. He changed the
formatting of the OP's code (the original was better). He changed a
variable name; the new name was clearer, but he didn't bother to say
that. This is unacceptable behavior, and I don't choose to sit
quietly by and let other readers be lied to.

If you don't like our replies, feel free to ignore them. Killfile us
if that makes you happy.

As for your obscene language, it doesn't particularly bother me,
especially if it's used creatively (though I try to avoid it in public
forums); you're just not very good at it.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
CBFalconer
Guest
 
Posts: n/a
#29: Nov 14 '05

re: Trying to understand pointers for function paramaters


Mabden wrote:[color=blue]
>[/color]
.... snip ...[color=blue]
>
> Where's your input? What is your content?
>
> Nothing!
>
> Fuck off![/color]

PLONK

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


Mabden
Guest
 
Posts: n/a
#30: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Keith Thompson" <kst-u@mib.org> wrote in message
news:ln1xggavx6.fsf@nuthaus.mib.org...[color=blue]
> "Mabden" <mabden@sbc_global.net> writes:[color=green]
> > "CBFalconer" <cbfalconer@yahoo.com> wrote in message
> > news:415B8170.4891BC87@yahoo.com...[color=darkred]
> >> Keith Thompson wrote:
> >> > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
> >> >
> >> ... snip mangled quote ...
> >> >
> >> > Damn it, Tisdale, that's not what he wrote. Here's what Richard
> >> > Hengeveld *actually* wrote in the article to which you replied:
> >> >
> >> ... snip details ...
> >> >
> >> > You've done this before, and you've been called on it. I have no
> >> > realistic expectation that you're going to change your ways this
> >> > time either. I'm posting this mostly as a warning to other[/color][/color][/color]
readers.[color=blue][color=green][color=darkred]
> >> >
> >> > If E. Robert Tisdale claims that someone else has written[/color][/color][/color]
something[color=blue][color=green][color=darkred]
> >> > in a previous article, don't believe it unless you've verified it
> >> > by reading the actual article that he claims to be quoting.[/color][/color][/color]
Trust[color=blue][color=green][color=darkred]
> >> > him at your own risk.
> >>
> >> And just when I thought Trollsdale was showing signs of
> >> reformation. He seems to be a dedicated recidivist. Can we apply
> >> the 'three strikes' law somehow?
> >>[/color]
> > Shut up! It was the same function with a variable changed.
> >
> > Where's your input? What is your content?
> >
> > Nothing!
> >
> > Fuck off![/color]
>
> Mabden, whoever you are, I am sick and tired of your insults. You've
> sometimes shown signs of being worth talking to, but if I had a
> killfile, you would have been in it several times over by now.[/color]

Well, stop trolling Tisdale unless you post actual content.
[color=blue]
> Tisdale ....[/color]

Get over it.
[color=blue]
> If you don't like our replies, feel free to ignore them. Killfile us
> if that makes you happy.[/color]

Ditto.
[color=blue]
> As for your obscene language, it doesn't particularly bother me,
> especially if it's used creatively (though I try to avoid it in public
> forums); you're just not very good at it.[/color]

Well, I use strong language with my friends (yes, I have some...) and
sometimes forget how some posters don't in their Real Life (tm).

I just have so many newsgroups to get through and a limited timeslice.
To have to read a long post about how this function was changed from "i"
to "p" and then compare them, and then find no difference, and then
realize, "Oh, it's just KT on his period again" gets really old.

Can't you just killfile Tisdale and be done with it, Nanny?

--
Mabden


Old Wolf
Guest
 
Posts: n/a
#31: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> wrote:[color=blue]
> "Flash Gordon" <spam@flash-gordon.me.uk> wrote:[color=green]
> > CBFalconer <cbfalconer@yahoo.com> wrote:[color=darkred]
> > > Keith Thompson wrote:
> > > > If E. Robert Tisdale claims that someone else has written
> > > > something in a previous article, don't believe it unless
> > > > you've verified it by reading the actual article that he
> > > > claims to be quoting. Trust
> > > > him at your own risk.
> > > And just when I thought Trollsdale was showing signs of
> > > reformation. He seems to be a dedicated recidivist. Can we apply
> > > the 'three strikes' law somehow?[/color]
> > You mean if any of us meet him we get to strike him three times? :-)[/color]
>
> Shut up![/color]

We seem to have a Trollsdale apologist!
Mabden
Guest
 
Posts: n/a
#32: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Old Wolf" <oldwolf@inspire.net.nz> wrote in message
news:843a4f78.0410031235.80d26fd@posting.google.co m...
[color=blue]
> We seem to have a Trollsdale apologist![/color]

Sad, aren't I?

--
Mabden


CBFalconer
Guest
 
Posts: n/a
#33: Nov 14 '05

re: Trying to understand pointers for function paramaters


Old Wolf wrote:[color=blue]
> "Mabden" <mabden@sbc_global.net> wrote:[color=green]
>> "Flash Gordon" <spam@flash-gordon.me.uk> wrote:[color=darkred]
>>> CBFalconer <cbfalconer@yahoo.com> wrote:
>>>> Keith Thompson wrote:
>>>>
>>>>> If E. Robert Tisdale claims that someone else has written
>>>>> something in a previous article, don't believe it unless
>>>>> you've verified it by reading the actual article that he
>>>>> claims to be quoting. Trust
>>>>> him at your own risk.
>>>>
>>>> And just when I thought Trollsdale was showing signs of
>>>> reformation. He seems to be a dedicated recidivist. Can we apply
>>>> the 'three strikes' law somehow?
>>>
>>> You mean if any of us meet him we get to strike him three times? :-)[/color]
>>
>> Shut up![/color]
>
> We seem to have a Trollsdale apologist![/color]

Not here any more. I awarded him the Royal Order of the PLONK.

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

John Bode
Guest
 
Posts: n/a
#34: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> wrote in message news:<NTP7d.5780$nj.5314@newssvr13.news.prodigy.co m>...[color=blue]
> "CBFalconer" <cbfalconer@yahoo.com> wrote in message
> news:415B8170.4891BC87@yahoo.com...[color=green]
> > Keith Thompson wrote:[color=darkred]
> > > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
> > >[/color][/color]
> ... snip mangled quote ...[color=green][color=darkred]
> > >
> > > Damn it, Tisdale, that's not what he wrote. Here's what Richard
> > > Hengeveld *actually* wrote in the article to which you replied:
> > >[/color][/color]
> ... snip details ...[color=green][color=darkred]
> > >
> > > You've done this before, and you've been called on it. I have no
> > > realistic expectation that you're going to change your ways this
> > > time either. I'm posting this mostly as a warning to other readers.
> > >
> > > If E. Robert Tisdale claims that someone else has written something
> > > in a previous article, don't believe it unless you've verified it
> > > by reading the actual article that he claims to be quoting. Trust
> > > him at your own risk.[/color]
> >
> > And just when I thought Trollsdale was showing signs of
> > reformation. He seems to be a dedicated recidivist. Can we apply
> > the 'three strikes' law somehow?
> >[/color]
> Shut up! It was the same function with a variable changed.
>[/color]

Even so, Tisdale should have marked his changes. It raises red flags
with me because I've dealt with posters in other fora who
*significantly* edit quoted material for patently dishonest purposes
(i.e., change a withering criticism into wholehearted support).

If you edit quoted material *FOR ANY REASON*, even if it's just to
change a stinking variable name, you should mark those edits
*somehow*.

When someone comes along to read the thread after the original article
has fallen off the server, what they'll be reading is Tisdale's
unmarked edit of the original, and if that reader has problems with
Tisdale's style or corrections, they'll erroneously attribute those
problems to the OP. That doesn't help the OP much.
[color=blue]
> Where's your input? What is your content?
>
> Nothing!
>
> Fuck off![/color]

Where's *your* input? What is *your* content?
Mabden
Guest
 
Posts: n/a
#35: Nov 14 '05

re: Trying to understand pointers for function paramaters


"John Bode" <john_bode@my-deja.com> wrote in message
news:43618c0e.0410040626.47db2109@posting.google.c om...[color=blue]
> "Mabden" <mabden@sbc_global.net> wrote in message[/color]
news:<NTP7d.5780$nj.5314@newssvr13.news.prodigy.co m>...[color=blue][color=green]
> > "CBFalconer" <cbfalconer@yahoo.com> wrote in message
> > news:415B8170.4891BC87@yahoo.com...[color=darkred]
> > > Keith Thompson wrote:
> > > > "E. Robert Tisdale" <E.Robert.Tisdale@jpl.nasa.gov> writes:
> > > >[/color]
> > ... snip mangled quote ...[color=darkred]
> > > >
> > > > Damn it, Tisdale, that's not what he wrote. Here's what Richard
> > > > Hengeveld *actually* wrote in the article to which you replied:
> > > >[/color]
> > ... snip details ...[color=darkred]
> > > >
> > > > You've done this before, and you've been called on it. I have[/color][/color][/color]
no[color=blue][color=green][color=darkred]
> > > > realistic expectation that you're going to change your ways this
> > > > time either. I'm posting this mostly as a warning to other[/color][/color][/color]
readers.[color=blue][color=green][color=darkred]
> > > >
> > > > If E. Robert Tisdale claims that someone else has written[/color][/color][/color]
something[color=blue][color=green][color=darkred]
> > > > in a previous article, don't believe it unless you've verified[/color][/color][/color]
it[color=blue][color=green][color=darkred]
> > > > by reading the actual article that he claims to be quoting.[/color][/color][/color]
Trust[color=blue][color=green][color=darkred]
> > > > him at your own risk.
> > >
> > > And just when I thought Trollsdale was showing signs of
> > > reformation. He seems to be a dedicated recidivist. Can we apply
> > > the 'three strikes' law somehow?
> > >[/color]
> > Shut up! It was the same function with a variable changed.
> >[/color]
>
> Even so, Tisdale should have marked his changes. It raises red flags
> with me because I've dealt with posters in other fora who
> *significantly* edit quoted material for patently dishonest purposes
> (i.e., change a withering criticism into wholehearted support).
>
> If you edit quoted material *FOR ANY REASON*, even if it's just to
> change a stinking variable name, you should mark those edits
> *somehow*.
>
> When someone comes along to read the thread after the original article
> has fallen off the server, what they'll be reading is Tisdale's
> unmarked edit of the original, and if that reader has problems with
> Tisdale's style or corrections, they'll erroneously attribute those
> problems to the OP. That doesn't help the OP much.
>[color=green]
> > Where's your input? What is your content?
> >
> > Nothing!
> >
> > Fuck off![/color]
>
> Where's *your* input? What is *your* content?[/color]

Too subtle for you? I can be that way, as I wouldn't wish to offend.

I was saying that a no content post wastes my time, and that I'm a Big
Boy and can distinguish a good post from a bad post all on my own. I
don't need someone following along to say, "Hey, that last post you read
might not be fully accurate! I don't want you to believe every word of
that last post! Hey, something on the internet may be misrepresenting
itself as fact, when in fact it is fiction! There's this one guy, and
you know, for some reason he changes everything he touches, and DON'T
LISTEN TO HIM!!!!! PLEEEEEZZZZEEEE!!!! --- There, I feel good about
myself because I've warned the world!"

That is what I object to.

--
Mabden


Default User
Guest
 
Posts: n/a
#36: Nov 14 '05

re: Trying to understand pointers for function paramaters


Mabden wrote:

[color=blue]
> Well, stop trolling Tisdale unless you post actual content.[/color]


I thought Mabden was starting to get a clue, but has gone berserk over
the weekend.


*plonk*




Brian Rodenborn
Old Wolf
Guest
 
Posts: n/a
#37: Nov 14 '05

re: Trying to understand pointers for function paramaters


CBFalconer <cbfalconer@yahoo.com> wrote:[color=blue]
> Old Wolf wrote:[color=green]
> > "Mabden" <mabden@sbc_global.net> wrote:
> >[color=darkred]
> >> Shut up![/color]
> >
> > We seem to have a Trollsdale apologist![/color]
>
> Not here any more. I awarded him the Royal Order of the PLONK.[/color]

So you've given him a ROP to hang himself? :-)
Mabden
Guest
 
Posts: n/a
#38: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Old Wolf" <oldwolf@inspire.net.nz> wrote in message
news:843a4f78.0410041228.eca0909@posting.google.co m...[color=blue]
> CBFalconer <cbfalconer@yahoo.com> wrote:[color=green]
> > Old Wolf wrote:[color=darkred]
> > > "Mabden" <mabden@sbc_global.net> wrote:
> > >
> > >> Shut up!
> > >
> > > We seem to have a Trollsdale apologist![/color]
> >
> > Not here any more. I awarded him the Royal Order of the PLONK.[/color]
>
> So you've given him a ROP to hang himself? :-)[/color]

My butt still hurts...

--
Mabden


Mabden
Guest
 
Posts: n/a
#39: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Default User" <first.last@boeing.com.invalid> wrote in message
news:I52MKv.HE@news.boeing.com...[color=blue]
> Mabden wrote:
>
>[color=green]
> > Well, stop trolling Tisdale unless you post actual content.[/color]
>
>
> I thought Mabden was starting to get a clue, but has gone berserk over
> the weekend.[/color]

OK, I do tend to do that. My bad.
[color=blue]
>
> *plonk*[/color]


Why not just plonk Tisdale? Then you won't complain about minutia (sp?)
and I won't feel it necessary to respond what a bunch a whinging
bastards you all are...

--
Mabden


Flash Gordon
Guest
 
Posts: n/a
#40: Nov 14 '05

re: Trying to understand pointers for function paramaters


On Tue, 05 Oct 2004 08:47:23 GMT
"Mabden" <mabden@sbc_global.net> wrote:

<snip>
[color=blue]
> Why not just plonk Tisdale? Then you won't complain about minutia
> (sp?) and I won't feel it necessary to respond what a bunch a whinging
> bastards you all are...[/color]

Tisdale doesn't get plonked by a lot of people because if no one pointed
out his errors people who did not know any better might believe him and
have problems as a result.

So people who are gratuitously insulting but either provide no advice or
correct advice get plonked, people who provide incorrect advice
generally don't get plonked even if they are gratuitously rude.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Richard Bos
Guest
 
Posts: n/a
#41: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> wrote:
[color=blue]
> "Default User" <first.last@boeing.com.invalid> wrote in message
> news:I52MKv.HE@news.boeing.com...[color=green]
> > *plonk*[/color]
>
> Why not just plonk Tisdale? Then you won't complain about minutia (sp?)[/color]

Because changing someone's post behind his back is _not_ a minutium. It
is a serious matter...
[color=blue]
> and I won't feel it necessary to demonstrate what a whinging
> bastard I am...[/color]

....if you see what I mean.

Richard
Michael Mair
Guest
 
Posts: n/a
#42: Nov 14 '05

re: Trying to understand pointers for function paramaters



Richard Bos wrote:[color=blue]
> "Mabden" <mabden@sbc_global.net> wrote:[color=green]
>>"Default User" <first.last@boeing.com.invalid> wrote in message
>>news:I52MKv.HE@news.boeing.com...
>>[color=darkred]
>>>*plonk*[/color]
>>
>>Why not just plonk Tisdale? Then you won't complain about minutia (sp?)[/color]
>
> Because changing someone's post behind his back is _not_ a minutium. It
> is a serious matter...
>[color=green]
>>and I won't feel it necessary to demonstrate what a whinging
>>bastard I am...[/color]
>
> ...if you see what I mean.[/color]

Oh no, must I now plonk you, Richard, for not saying it clearly... ;-)

Nice one, btw


--Michael

Mabden
Guest
 
Posts: n/a
#43: Nov 14 '05

re: Trying to understand pointers for function paramaters



"Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
news:nr7a32xsc8.ln2@brenda.flash-gordon.me.uk...[color=blue]
> On Tue, 05 Oct 2004 08:47:23 GMT
> "Mabden" <mabden@sbc_global.net> wrote:
>
> <snip>
>[color=green]
> > Why not just plonk Tisdale? Then you won't complain about minutia
> > (sp?) and I won't feel it necessary to respond what a bunch a[/color][/color]
whinging[color=blue][color=green]
> > bastards you all are...[/color]
>
> Tisdale doesn't get plonked by a lot of people because if no one[/color]
pointed[color=blue]
> out his errors people who did not know any better might believe him[/color]
and[color=blue]
> have problems as a result.[/color]

It's called "the internet" not "the gospel".
[color=blue]
>
> So people who are gratuitously insulting but either provide no advice[/color]
or[color=blue]
> correct advice get plonked, people who provide incorrect advice
> generally don't get plonked even if they are gratuitously rude.[/color]


Well, it's nice to know that correct advice is plonkable. I'll try to
steer clear of providing any of that. So, in your world, do people say
"Goodbye" when you meet them and "Hello" when you depart?

Anyhow, I was just annoyed (again) at the bandwidth waste, and lack of
sleep (ok, too much beer) made me think it was important to comment.
Forget it and let's let this thread die.

--
Mabden


Keith Thompson
Guest
 
Posts: n/a
#44: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> writes:[color=blue]
> "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
> news:nr7a32xsc8.ln2@brenda.flash-gordon.me.uk...[/color]
[...][color=blue][color=green]
>> So people who are gratuitously insulting but either provide no
>> advice or correct advice get plonked, people who provide incorrect
>> advice generally don't get plonked even if they are gratuitously
>> rude.[/color]
>
> Well, it's nice to know that correct advice is plonkable. I'll try to
> steer clear of providing any of that. So, in your world, do people say
> "Goodbye" when you meet them and "Hello" when you depart?[/color]

The point is that we need to keep an eye on posters who post incorrect
advice, so newbies aren't misled. A lot of people would like to plonk
ERT, for example, but continue to read his articles so they can
correct his misstatements. Someone who is insufferably rude but
either offers correct advice or doesn't offer advice at all can be
safely ignored, since he's not likely to mislead anyone. It's how the
newsgroup defends itself.
[color=blue]
> Anyhow, I was just annoyed (again) at the bandwidth waste, and lack of
> sleep (ok, too much beer) made me think it was important to comment.
> Forget it and let's let this thread die.[/color]

Do us all a favor and don't post when you're drunk or hung over. This
isn't just a conversation that everybody is going to forget; everthing
you post here is archived permanently. The impression you've given so
far is not a good one.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mabden
Guest
 
Posts: n/a
#45: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Keith Thompson" <kst-u@mib.org> wrote in message
news:lnacv17xn9.fsf@nuthaus.mib.org...[color=blue]
> "Mabden" <mabden@sbc_global.net> writes:[color=green]
> > "Flash Gordon" <spam@flash-gordon.me.uk> wrote in message
> > news:nr7a32xsc8.ln2@brenda.flash-gordon.me.uk...[/color]
> [...][color=green][color=darkred]
> >> So people who are gratuitously insulting but either provide no
> >> advice or correct advice get plonked, people who provide incorrect
> >> advice generally don't get plonked even if they are gratuitously
> >> rude.[/color]
> >
> > Well, it's nice to know that correct advice is plonkable. I'll try[/color][/color]
to[color=blue][color=green]
> > steer clear of providing any of that. So, in your world, do people[/color][/color]
say[color=blue][color=green]
> > "Goodbye" when you meet them and "Hello" when you depart?[/color]
>
> The point is that we need to keep an eye on posters who post incorrect
> advice, so newbies aren't misled. A lot of people would like to plonk
> ERT, for example, but continue to read his articles so they can
> correct his misstatements. Someone who is insufferably rude but
> either offers correct advice or doesn't offer advice at all can be
> safely ignored, since he's not likely to mislead anyone. It's how the
> newsgroup defends itself.
>[color=green]
> > Anyhow, I was just annoyed (again) at the bandwidth waste, and lack[/color][/color]
of[color=blue][color=green]
> > sleep (ok, too much beer) made me think it was important to comment.
> > Forget it and let's let this thread die.[/color]
>
> Do us all a favor and don't post when you're drunk or hung over. This
> isn't just a conversation that everybody is going to forget; everthing
> you post here is archived permanently. The impression you've given so
> far is not a good one.[/color]

You've never Googled "Mabden" have you?! (I don't mean my posts)

--
Mabden


Keith Thompson
Guest
 
Posts: n/a
#46: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Mabden" <mabden@sbc_global.net> writes:[color=blue]
> "Keith Thompson" <kst-u@mib.org> wrote in message
> news:lnacv17xn9.fsf@nuthaus.mib.org...[color=green]
>> "Mabden" <mabden@sbc_global.net> writes:[/color][/color]
[...][color=blue][color=green][color=darkred]
>> > Anyhow, I was just annoyed (again) at the bandwidth waste, and
>> > lack of sleep (ok, too much beer) made me think it was important
>> > to comment. Forget it and let's let this thread die.[/color]
>>
>> Do us all a favor and don't post when you're drunk or hung over. This
>> isn't just a conversation that everybody is going to forget; everthing
>> you post here is archived permanently. The impression you've given so
>> far is not a good one.[/color]
>
> You've never Googled "Mabden" have you?! (I don't mean my posts)[/color]

No, I hadn't. Now I have. It appears to be a reference to the
fantasy works of Michael Moorcock. I'd ask you what the point is if I
cared.

I'll post to this thread again only if there's a technical C issue to
be discussed.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mark McIntyre
Guest
 
Posts: n/a
#47: Nov 14 '05

re: Trying to understand pointers for function paramaters


On Tue, 05 Oct 2004 20:46:59 GMT, in comp.lang.c , "Mabden"
<mabden@sbc_global.net> wrote:
[color=blue]
>You've never Googled "Mabden" have you?! (I don't mean my posts)[/color]

Why would anyone care about you fantasising about being a Moorcock
character? This is clc, not alt.weird.fantasy.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Mabden
Guest
 
Posts: n/a
#48: Nov 14 '05

re: Trying to understand pointers for function paramaters


"Keith Thompson" <kst-u@mib.org> wrote in message
news:lnfz4s7tsz.fsf@nuthaus.mib.org...[color=blue]
> "Mabden" <mabden@sbc_global.net> writes:[color=green]
> > "Keith Thompson" <kst-u@mib.org> wrote in message
> > news:lnacv17xn9.fsf@nuthaus.mib.org...[color=darkred]
> >> "Mabden" <mabden@sbc_global.net> writes:[/color][/color]
> [...][color=green][color=darkred]
> >> > Anyhow, I was just annoyed (again) at the bandwidth waste, and
> >> > lack of sleep (ok, too much beer) made me think it was important
> >> > to comment. Forget it and let's let this thread die.
> >>
> >> Do us all a favor and don't post when you're drunk or hung over.[/color][/color][/color]
This[color=blue][color=green][color=darkred]
> >> isn't just a conversation that everybody is going to forget;[/color][/color][/color]
everthing[color=blue][color=green][color=darkred]
> >> you post here is archived permanently. The impression you've given[/color][/color][/color]
so[color=blue][color=green][color=darkred]
> >> far is not a good one.[/color]
> >
> > You've never Googled "Mabden" have you?! (I don't mean my posts)[/color]
>
> No, I hadn't. Now I have. It appears to be a reference to the
> fantasy works of Michael Moorcock. I'd ask you what the point is if I
> cared.
>[/color]

Not just Moorcock, it's used elsewhere. It is generally a crude,
actively cruel, and mischievous race or spirit. The point (not that you
asked or cared) is that you are complaining about my "behaviour", but my
signature should be a hint that I'm not entirely housebroken.

But, I'm not hopeless. I just tend to slip back a step for every two
steps forward...
[color=blue]
> I'll post to this thread again only if there's a technical C issue to
> be discussed.[/color]

Well, I tried to halt the thread once already...

--
Mabden


Mark McIntyre
Guest
 
Posts: n/a
#49: Nov 14 '05

re: Trying to understand pointers for function paramaters


On Wed, 06 Oct 2004 00:35:49 GMT, in comp.lang.c , "Mabden"
<mabden@sbc_global.net> wrote:
[color=blue]
>Not just Moorcock, it's used elsewhere. It is generally a crude,
>actively cruel, and mischievous race or spirit. The point (not that you
>asked or cared) is that you are complaining about my "behaviour", but my
>signature should be a hint that I'm not entirely housebroken.[/color]

Actually, what it shows is that you're extremely childish if you think that
naming yourself after a fantasy creature that you like to imagine yourself
being is even remotely relevant in a technical group.

[color=blue][color=green]
>> I'll post to this thread again only if there's a technical C issue to
>> be discussed.[/color][/color]

Just stick to C.
[color=blue]
>Well, I tried to halt the thread once already...[/color]

I'm not aware that you own usenet. If you want to stop a thread, then
you're being hitlerian and fascist.*

* that comment may go over your head tho.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Thomas Stegen
Guest
 
Posts: n/a
#50: Nov 14 '05

re: Trying to understand pointers for function paramaters


Richard Hengeveld wrote:[color=blue]
>
> I'm not trying to solve a problem. I'm just trying to understand C.
> In a function without pointer arguments, the argument(s) of that function
> are set by value passing:
>
> f(int i)
> {
> printf("%d", i);
> }
>
> int main()
> {
> int i;
> f(i);
> return 0;
> }
>
> I just don't understand why this is (a little bit) different with pointer
> arguments.
>
>[/color]

It's not different at all really.

Grab:
1. A piece of paper.
2. A pen.
3. A house on a street.

The piece of paper is now your pointer variable, (int *p for example).
The pen is your assignment operator.
The house is your int object (int house for example).

But aside from that, if you want to tell anyone how to get to your house
do you pass them the whole house? I wouldn't think so (but you never
know). So what do you do? You write it down on a piece of paper. No, you
do not write down the house, you write down the address of the house.
Now your friends can come over after you give them that piece of paper.
Can they do anything to your house, like enter it, set it on fire just
by having your piece of paper? No they can't, they have to go to your
house first.

So essentially, the house has (at least) two aspects to it, the house
itself and its address. You have to make it clear which you want. With
variables in C it's the same thing. They have a value and an address.
You have to be clear on which you want. The & operator seems apt in
telling the compiler what it is you require. The piece of paper as well,
you have to be clear on whether you want to change the piece of paper
or the thing that is at the address it holds. In other words, how do you
tell your program to set fire to the piece of paper, how about whatever
is at the address written down? Well you simply say, set fire to this
piece of paper, or in the latter case you say set fire to what resides
at the address written down on this piece of paper.

See, the second statement a bit complex than the first. So should
require some more syntax as well. Also the syntax makes sense when
you consider that pointers are completely normal variables. When you
want something else than the value stored in a variable then you
need to tell the compiler that.


HTH.
--
Thomas.
Closed Thread