D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: Character arrays was Re: [LUG] C - global arrays



Simon Waters wrote:

My C isn't getting any better..... someone sent me a patch....

.h has
static const char * const bookbin[] = {

Urm in an attempt to answer my own question....

static - only known in this file (.h - and presumably those that
include it).

const (the pointers don't change)

 char (characters)

 * (pointers to)

  const (make the characters as well as the pointers read only)

   bookbin[] (an array).

So we have an unchanging array of pointers (bookbin) which point
to unchanging strings known only to files that include this
header file.

  "string",
 .....strings .....
  NULL };

.c has
const char **booktry;

A constant pointer to a string, but we want a changing pointer
to constant strings.

So I tried;

char * const *booktry

A pointer to a constant character pointer, which compiles
without warning, and works.....

Although I'm still not 100% sure this is correct in a strongly
typed sense. I am tempted to rewrite the whole loop without
pointer arithmetic, not as if it is performance critical. I'm
now more convinced then ever C sucks as an application
programming language - heck this should be simple stuff, it
should only be looping over a list of file names - or is
everyone taking the mickey?

Meanwhile - cvs commit - now it compiles and runs without
warnings.

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly