• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] A bit confused on pointers...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] A bit confused on pointers...


  • Subject: Re: [OT] A bit confused on pointers...
  • From: Greg Herlihy <email@hidden>
  • Date: Fri, 30 Dec 2005 11:45:40 -0500




On 12/30/05 5:45 AM, "Camillo Lugaresi" <email@hidden> wrote:

> On 30/dic/05, at 11:10, Andreas Mayer wrote:
>>
>> Am 29.12.2005 um 21:39 Uhr schrieb Clark Cox:
>>
>>> what is confusing about the syntax?
>>>
>>> If (ptr) is a pointer, then (*ptr) is whatever it points at
>>
>> Umm... what's *not* confusing about that syntax?
>>
>> * is usually associated with multiplication.
>>
>> And as Pontus pointed out, it doesn't help that the same symbol is
>> used in the declaration of pointers. To make things worse, it's
>> customary to write int *ptr instead of int* ptr, which would
>> be more accurate in my opinion. The '*' modifies the type, after
>> all, not the identifier.
>
> Wrong!
>
> int *a, b;
>
> What type is b? int. If you want two pointers to int, write:
>
> int *a, *b;

C++ programmers will tend to put the * or & (for references) near the type
(where it makes more sense for readability and maintainability.) And since
the entire type-before-the-name convention in C/C++ is something of a failed
experiment, the declarations are best made on separate lines for the same
reasons:

int* b;
int* a;
>
> It's also useful when declaring types:
>
> typedef struct {
> int x;
> int y;
> } Point, *PointPtr;

A C++ programmer would likely name the struct "Point" and use a typedef to
name PointPtr.

>> Then there is the & operator, which is often used in conjunction
>> with pointers; and of course, this character does have a different
>> meaning when used as a binary operator.
>
> But there's never any ambiguity about whether the operator is unary
> or binary in an expression.

Never? The * operator is inherently ambiguous. Consider:

a * b;

Is b a pointer to a or is the expression a multiplied by b? Without any
context it is impossible to know for sure. Either interpretation constitutes
a legal expression in C.

Greg


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [OT] A bit confused on pointers...
      • From: Camillo Lugaresi <email@hidden>
    • Re: [OT] A bit confused on pointers...
      • From: Alastair Houghton <email@hidden>
    • Re: [OT] A bit confused on pointers...
      • From: Steve Checkoway <email@hidden>
References: 
 >Re: [OT] A bit confused on pointers... (From: Camillo Lugaresi <email@hidden>)

  • Prev by Date: Re: [OT] A bit confused on pointers...
  • Next by Date: Re: [OT] A bit confused on pointers...
  • Previous by thread: Re: [OT] A bit confused on pointers...
  • Next by thread: Re: [OT] A bit confused on pointers...
  • Index(es):
    • Date
    • Thread