[Asterisk-Dev] ast_flags question

Kevin P. Fleming kpfleming at starnetworks.us
Fri Jan 7 08:37:23 MST 2005


Andrew Thompson wrote:
> I've been looking at bug 3083 
> (http://bugs.digium.com/bug_view_page.php?bug_id=0003083), and am 
> wondering if there has been discussion on whether an int is big enough 
> to hold everything that we might want to store, or what to do when there 
>  are more than 32 things that can be reduced to flags? (OK, when I 
> originally wrote this question, I thought it as 16 bits, but anyway, 
> isn't there always just one more thing?)

Yes, any specific module/struct that needs more than 32 flags will have 
to declare a second flags variable in that struct.

> I see in bug 3136 
> (http://bugs.digium.com/bug_view_page.php?bug_id=0003136) that a struct 
> is being used to hold the flags variable, which I am guessing means an 
> "unsigned int moreflags" could be added to handle more flags, but I see 
> other code that just uses an int.

The "struct ast_flags" is used when you need a place to store flags 
outside of any existing structure (temporary copies and such). Yes, that 
struct could be extended, just as could any other struct that has a 
"flags" variable now.

> Also, there was a note in 3136 that suggested the use of unsigned int 
> instead of int, but I see in bug 3083 that an int was used for the flags 
> variable. If this was going to be defined locally, shouldn't it have 
> been unsigned as well? And, is there a reason why the struct was not used?

The way the flags macros are currently written, using a 
struct-inside-a-struct would just increase the amount of work for the 
coder, for no additional gain. Also, it would force _all_ users of flags 
to allocate 64 bits worth, even if they don't need them (if the struct 
was extended to hold two sets of flags).

As far as signed vs. unsigned, that was my suggestion, and Russell has 
already converted chan_sip and chan_iax2 over to using "unsigned int". 
If you know of any more places in current CVS that are using signed ints 
  for flags, please post bugs in Mantis (with patches if you can). It's 
only really important when you try to use bit number 31 or 32 in the 
int, because then the compiler will sign-extend the value behind your 
back :-)

I may try to modify the flags macros to generate compiler warnings if 
someone uses them against a signed int... stay tuned :-)



More information about the asterisk-dev mailing list