Please Please Help! - pointer notation 
Author Message
 Please Please Help! - pointer notation

Quote:

[snip snip]
> I've read my C book. I've gotten th C FAQ. I've read the file
> "ptrtutor.txt" a tutorial on pointers. But I havn't seen explained the
> following. Can you help?

Probably time to throw at least the book and the `.txt' outta the window ;-)

Quote:

> Sometimes when prototyping a function the function name is pre-fixed
> by an asterisk. Why? What does it mean? This is a quote from the
> pointer tutorial text by Ted Jensen...

Well, go from here:
`int foo()' means `foo()' is a function returning an `int`. Right? Right.
`char *str' means `str' is a pointer to `char'. Right? Right.

Let's mix the previous ones a bit up and we get:
`char *bar()' means 'bar()' is a function returning a pointer to `char' ... !

(I'd rather write it like `char* bar()', but that's just my $0.02)

Quote:

[snip snip]

> Putting an asterisk before a variable name declares it as a pointer
> variable. Putting one before the variable in use means you want to
> access the data pointed to. Why is there sometimes an asterisk AFTER a
> variable?

> (And I can't find a quote at the moment...)

Let me give you one:

int main()
{
        int a, b;

        a = 4;
        b = a * 3;      /* Now the asterisk's after a variable?? */

        return 1;

Quote:
}

Seriously, I never came across an asterisk after a variable that meant other than
multiply. Might be my inexperience as well.

Hope the more serious parts might help,
        Guus Leeuw jr.



Wed, 12 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation
Hi.

I'm reposting this as I've had no replies and I'm still without the
information.

I've read my C book. I've gotten th C FAQ. I've read the file
"ptrtutor.txt" a tutorial on pointers. But I havn't seen explained the
following. Can you help?

Sometimes when prototyping a function the function name is pre-fixed
by an asterisk. Why? What does it mean? This is a quote from the
pointer tutorial text by Ted Jensen...

+++++++++++++++++++++++++++++++++++++++++++++

"    Of course, what the above program illustrates is a simple way
of copying a string.  After playing with the above until you have
a good understanding of what is happening, we can proceed to
creating our own replacement for the standard strcpy() that comes
with C.  It might look like:

   char *my_strcpy(char *destination, char *source)
   {
        char *p = destination
        while (*source != '\0')
        {
           *p++ = *source++;
        }
        *p = '\0';
        return destination.
   }

    In this case, I have followed the practice used in the
standard routine of returning a pointer to the destination."

+++++++++++++++++++++++++++++++++++++++++++++

I can't find an explanation fro the asterisk BEFORE THE FUNCTION NAME.

Putting an asterisk before a variable name declares it as a pointer
variable. Putting one before the variable in use means you want to
access the data pointed to. Why is there sometimes an asterisk AFTER a
variable?

(And I can't find a quote at the moment...)

All hint's will be of GREAT use. Thanks.

---
Mic.
From windy and damp Worthing; England.

(I just lost 4 fence panels to the wind here! The cost of
replacing them could have bought me a new windows compiler!)



Wed, 12 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation

Quote:

> Hi.

> I'm reposting this as I've had no replies and I'm still without the
> information.

> I've read my C book. I've gotten th C FAQ. I've read the file
> "ptrtutor.txt" a tutorial on pointers. But I havn't seen explained the
> following. Can you help?

> Sometimes when prototyping a function the function name is pre-fixed
> by an asterisk. Why? What does it mean? This is a quote from the
> pointer tutorial text by Ted Jensen...

  Functions are declared as

<return-type> <func-name>([<param-list>]);

  so a declaration like

char *foo(char *);

  means that the function foo has a return type of char * (read "pointer
to char") and takes a parameter of type char *.

  It could also be written as char* foo( char* );.

Quote:
> Putting an asterisk before a variable name declares it as a pointer
> variable.

  You can think of variable declarations the same way as function
declarations (or definitions).

int *ip;

 declares ip as being of type int * ("pointer to int").

Quote:
> Why is there sometimes an asterisk AFTER a variable?

  * is also the multiplication operator. That's the only explanation I
can think of.  p * 5  means "multiply p by 5."  It can also be written
p*5, p* 5, and p *5, although the latter 2 are extremely rare.

/**James Robinson***********************            
  "An important goal of almost every graphics program is to draw pictures on
 the screen."    -- Neider, Davis & Woo, _OpenGL_Programming_Guide_, Chapter 10



Wed, 12 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation

Quote:

>Hi.
>I'm reposting this as I've had no replies and I'm still without the
>information.

etc...

And I had loads of e-mail replies this time. The answer was (as
always!) rather obvious, but I didn't realise that the absence of a
whitespace doesn't matter to the compiler.

Many thanks to you all. I hope I'll be able to DO the helping one day!

---
Mic.
From windy and damp Worthing; England.

(I just lost 4 fence panels to the wind here! The cost of
replacing them could have bought me a new windows compiler!)



Sat, 15 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation

Quote:

[snip snip]
> > (I'd rather write it like `char* bar()', but that's just my $0.02)

> Let me ask you one question, if I may.  We can, if we want,
> declare two variables in one declaration:

>   int i, j;

> How would you prefer to write a single declaration of two pointer
> variables, or two functions returning pointers?  (I'm not trying
> to give you a hard time; I'm just curious.)

Okay: My $0.02 ;-)

One declaration of two pointer variables would go like:
`int *a, *b;'.
One declarations of two functions returning pointers would not be
written. It would be two declarations.

I think it is rather confusing to write `char *foo(), *bar();'. Aand of
course you can go crazy and have 80 functions in one declaration...
It'll make a mess, I think.

It won't make a mess, though, when you have: `int *i1, ..., *i80;'.

Well, to make a longer story shorter, I just don't like the `*name'
notation for functions. Besides that, at the company where I work,
nobody uses the *name notation for functions but still for variables. So
for that environment, I'm just fine.

If, with another project, someone would favor the notation I don't
really like but kinda have to follow, I would do it, because it's
consistent.

Basically I don't really care what notation somebody uses, but when he
goes from
`int* i;' to 'int *j;' I would tell him to make up his mind.

Regards,
        Guus



Sun, 16 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation




 >
 >>And I had loads of e-mail replies this time. The answer was (as
 >>always!) rather obvious, but I didn't realise that the absence of a
 >>whitespace doesn't matter to the compiler.
 >
 >It does matter sometimes since some tokens are prefixes to other tokens,
 >for example / and /* so

This ain't fortran, after all.

The first Fortran compiler, completed after 18 person-years, began it's
treacherous process by removing whitespace from the source. Hence, the
statements

        DO I = 1,3              ( loop from 1 to 3 over variable I )

and
        DOI = 1.3               ( assignment to variable DOI )

both became

        DOI=1,3         and     DOI=1.3

Since DOI is a valid identifier, the Fortran compiler could not decide whether
to tokenize as DO I, or DOI until detecting the presence of the comma.

 >   a = b / *p;
 >
 >means something entirely different to
 >
 >   a = b /*p;

Not to mention:

        integer=3;              versus          int eger=3;

 >and consider what
 >
 >   x = y+++z;

Shoot. I was just perusing the ISO9899 in the library, but I forgot to check
whether it actually specifies that the longest lexeme always takes precedence
in the case of lexical ambiguity. Is this the case?

 >means. However in most cases there is no ambiguity and white-space makes
 >no difference.

Are you implying that it _is_ ambiguous rather than equivalent to x = y++ +z?
That would be rather unfortunate.
--



Sun, 16 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation

Quote:

>Sometimes when prototyping a function the function name is pre-fixed
>by an asterisk. Why? What does it mean? This is a quote from the
>pointer tutorial text by Ted Jensen...

A "*" before a function name the way you describe means that it returns a
pointer. ie:

char *Foo( void );

Foo is a function which returns a pointer to a char, or a "char *".
Remeber, the above means the same as:

char* Foo( void );

Which might be a little bit easier to understand. (The reason people tend
to put the space before the * rather than after has to do with the way *'s
are "bound" to variable names. Of course, this doesn't apply to functions,
but many people use the same spacing just to be consistent I guess...)

Quote:
>Putting an asterisk before a variable name declares it as a pointer
>variable. Putting one before the variable in use means you want to
>access the data pointed to. Why is there sometimes an asterisk AFTER a
>variable?

Because you want to multiply it with something?

--

                   Computer Science, University of Waterloo
               http://www.undergrad.math.uwaterloo.ca/~clgonsal/
                   http://www.csclub.uwaterloo.ca/~clgonsal/



Mon, 17 Aug 1998 03:00:00 GMT  
 Please Please Help! - pointer notation

 >KK: Are you implying that it _is_ ambiguous rather than equivalent to
 >x = y++ +z?
 >
 >I don't think so. The probable implication was that it is ambiguous to
 >the uninitiates human reader.

I checked up on it. Indeed, it is standardized that the longest lexeme is taken
from the input stream.
--



Fri, 21 Aug 1998 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Help - pointer notation please...

2. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

3. Please help!!!!Please help!!!!Please help!!!!

4. help: Guru needed please please please

5. HELP please on QUEUES!! please, please, please, please,please...

6. PLEASE PLEASE PLEASE PLEASE

7. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

8. PLEASE PLEASE HELP HELP...question on interleaving C functions

9. Dereference void pointer help, xxgdb help please

10. Please Please Help!!!!!!

11. ICloneable - Please help.....please....

12. simulate dragDrop of ListView Item -- Please Please Help!!!!

 

 
Powered by phpBB® Forum Software