Simon Fraser wrote:
> Another issue: ensure that global static data is const where possible;
> this allows the linker to place it in a read-only section of the DLL,
> that has file-mapping advantages (see bug
> <http://bugzilla.mozilla.org/show_bug.cgi?id=74803>).
>
> Example:
>
> Bad: static const char* kFoobar = "Foobar";
> Good: static const char* const kFoobar = "Foobar";
Best:
static const char kFoobar[] = "Foobar";
Otherwise you waste four bytes (on most platforms) on a const pointer
that serves no purpose, and may confuse sizeof users who wish to compute
the string length at compile time (see bug
http://bugzilla.mozilla.org/show_bug.cgi?id=72658).
So I would say Good, above, is Bad, still.
> Bad:
>
> static PRUint16 g_ufMappingTable[] = {
> #include "8859-2.uf"
> };
>
> Good:
>
> static PRUint16 const g_ufMappingTable[] = {
> #include "8859-2.uf"
> };
>
But remember that const and * and contravariant (ding!), so it seems
better style (and more consistent with your earlier style) to put the
const above _before_ the PRUint16 type, not after (and eerily near the
g_ufMappingTable declarator). If the table were an array of pointers to
PRUint16, you'd probably say 'static const PRUint16 *const
g_ufMappingTable[] = {...}' rather than 'static PRUint16 const * const
g_ufMappingTable[] = {...}'. The latter would be inferior,
stylistically, while still legal in C/C++.
/be