Re: [cc65] Using pointers to arrays

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2009-09-27 14:06:53
Hello Marc,

* On Sun, Sep 27, 2009 at 10:57:47AM +0200 Marc 'BlackJack Rintsch wrote:
 
> While it is possible to declare it in one step, I would prefer splitting 
> it up with a type definition.  Then it is easier to read and you don't 
> have to retype parts of the declaration when getting the size to 
> allocate.

While I prefer a typedef myself for better readability, too, I do not
take your argument for it:

> #include <stdio.h>
> #include <stdlib.h>
> 
> typedef char* A[32];
> A *list;
> 
> int main(void)
> {
>     list = calloc(1, sizeof(A));

Replace with

      list = calloc(1, sizeof *list);

IMHO, this is much more readable, and much more error proof (what if the
type of list changes from "A *" to "B *"?)

Regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://opencbm.sf.net/
http://www.trikaliotis.net/                     http://www.viceteam.org/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Sep 27 14:07:55 2009

This archive was generated by hypermail 2.1.8 : 2009-09-27 14:07:57 CEST