-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(Forgot to CC the list.

Also, my mailer seems to be screwing up the quotes. :(  -M)

Diego 'Flameeyes' Pettenò wrote:
| As for maintainability, while a character pointer is easier to handle
than a
| character array, modern compilers warns you if you tries to force
bigger data
| into an array:
|
| struct { char foo[2]; } bar[] { { "foobar" } };

Yes; but I still have to manually increment the size to an appropriate
value each time I add a bigger string; plus I'm wasting space for all
shorter strings (which applies more to bigger-than-two-element char arrays);

| There actually are quite a few differences, I've documented them on my
blog
| some time ago:
|
|
http://farragut.flameeyes.is-a-geek.org/articles/2007/12/19/array-of-pointers-and-array-of-arrays
|
http://farragut.flameeyes.is-a-geek.org/articles/2008/01/01/some-more-about-arrays-of-strings

As I understand it, you have two issues with things like:

~  static const char *additional_attributes[] = { ... }

The first is that, since additional_attributes[] itself isn't constant,
it will not reside in read-only memory, unlike the data its elements
point at. This is easily solved with:

~  static const char * const additional_attributes[] = { ... }

Which is better anyway, since it also prevents someone from accidentally
overwriting elements with something like:

~  if (additional_attributes[4] = "magic_attr) {
~                            /* ^ Whoops! */

The other is that there is the inefficiency of indirection, where the
code has to find the proper string by first finding the proper element
within the additional_attributes array, and then following _that_
pointer to the proper string.

The first solution makes good sense to me, particularly for its improved
correctness; but fixing the second problem seems like a
nano-optimization that doesn't bring sufficient efficiency benefits to
outweigh its drawbacks in maintainability.

Anyway, thanks for the information, and helpful suggestions. :)

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHom/y7M8hyUobTrERAkzEAJ9tV3ZbzLuqlfvZW2SLDa4YkZNJQgCeN4f5
905Ny2JMxt1hsWsgVcIGZtE=
=yvIE
-----END PGP SIGNATURE-----

Reply via email to