Re: Pointers

From: CBFalconer (cbfalconer_at_yahoo.com)
Date: 03/11/05


Date: Fri, 11 Mar 2005 15:52:16 GMT

Thomas Stegen wrote:
>
... snip ...
>
> One way to see the declaration syntax (losely as it is) is that you
> declare expression that evaluate to a certain type, char above.
>
> So you say *c evaluates to char. Sort of. I think it would be better
> to say:
>
> pointer_to_char_type a,b,c;
>
> Now all the above is of type char* (as it is now). The above can be
> achieved using a typedef of course, but we don't like hiding
> pointers in typedefs, do we?

I think that is an irrational attitude. We hide pointers all the
time with such things as:

    char *thingummy;

If we want to emphasise the pointerness we can write:

    char *thingptr;

and there is no reason not to do the same things, for the same
reasons, with types by:

    typedef char *thingamabob;
or
    typedef char *athingptr;

except that now there is no confusion with multiple definition in:

    athingptr a, b, c;

all of which are of type athingptr (or thingamabob if desired). It
is all part of decoupling code modules.

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


Relevant Pages

  • Re: Tip 27: CONST qualifiers on pointer array arguments to TCL functions
    ... 'const' to char** (or more generally, arrays of pointers) arguments. ... possible if the argv itself is non-const) will likely break things ...
    (comp.lang.tcl)
  • Re: size of pointer variables
    ... >>> around an extra bit for some reason, in which case the code will break. ... >>> void pointers, of course, are guaranteed to be able to hold any type. ... A compiler that can't use char* as a generic pointer is at best ...
    (comp.lang.c)
  • Re: sizeof(ptr) = ?
    ... A void * has the same representation as a char *. ... Char pointers which require additional data ... iff the default offset is 0. ...
    (comp.lang.c)
  • Re: Comments requested: brief summary of C
    ... ``A char holds a single byte. ... ``A string is a contiguous sequence of characters terminated ... pointed to by city. ... pointers and arrays are often used ...
    (comp.lang.c)
  • Re: Any way to take a word as input from stdin ?
    ... You want to sort many words, so you will need to store ... number of pointers to char (which can be reallocated if it proves to be ... The pointers to char ... That's why you use dynamic allocation - it means ...
    (comp.lang.c)

Loading