local array of structures not declared static

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

local array of structures not declared static

Denis Vlasenko-2
Hi,

krb5-1.4.3/src/lib/kadm5/logger.c:


                       /*
                         * If there is a facility present, then parse that.
                         */
                        if (cp2) {
                            const struct {
                                const char *name;
                                int value;
                            } facilities[] = {
                                { "AUTH",       LOG_AUTH        },
#ifdef  LOG_AUTHPRIV
                                { "AUTHPRIV",   LOG_AUTHPRIV    },
#endif  /* LOG_AUTHPRIV */
#ifdef  LOG_KERN
                                { "KERN",       LOG_KERN        },
#endif  /* LOG_KERN */


Shouldn't we add "static" before "const" here?
--
vda
_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev
Reply | Threaded
Open this post in threaded view
|

Re: local array of structures not declared static

Jeffrey Hutzelman


On Tuesday, December 06, 2005 04:27:47 PM +0200 Denis Vlasenko
<[hidden email]> wrote:

> Hi,
>
> krb5-1.4.3/src/lib/kadm5/logger.c:
>
>
>                        /*
>                          * If there is a facility present, then parse
> that.                          */
>                         if (cp2) {
>                             const struct {
>                                 const char *name;
>                                 int value;
>                             } facilities[] = {
>                                 { "AUTH",       LOG_AUTH        },
># ifdef  LOG_AUTHPRIV
>                                 { "AUTHPRIV",   LOG_AUTHPRIV    },
># endif  /* LOG_AUTHPRIV */
># ifdef  LOG_KERN
>                                 { "KERN",       LOG_KERN        },
># endif  /* LOG_KERN */
>
>
> Shouldn't we add "static" before "const" here?

I guess I'd be midly surprised if that actually had an effect on code
generation in this case.  But I don't see how it could hurt, either.
_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev
Reply | Threaded
Open this post in threaded view
|

Re: local array of structures not declared static

Kenneth G Raeburn
On Dec 8, 2005, at 13:56, Jeffrey Hutzelman wrote:
>> Shouldn't we add "static" before "const" here?
>
> I guess I'd be midly surprised if that actually had an effect on  
> code generation in this case.  But I don't see how it could hurt,  
> either.

I'd expect minor changes: Static storage references instead of  
automatic-variable references, and the initialization (probably a  
block-copy from static read-only storage) goes away.

I don't recall seeing any compiler automatically convert a const auto  
variable into a static one, and actually I'm not sure if it would be  
legitimate in all cases.  Perhaps if the address never leaked outside  
the current scope.

The kadmin code isn't multithreaded yet, but in multithreaded code,  
keeping the stack usage down is a good thing.  Generally the stacks  
for threads other than the initial one have much smaller size  
limits.  So, in general, this sort of change is probably a good  
thing.....

Ken
_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev