Falk Hueffner wrote: > Josh Triplett <[EMAIL PROTECTED]> writes: >>The sentinel attribute tells GCC to ensure that the argument list of a >>variadic function always ends with a final NULL argument. It should be >>possible to use this attribute for a variadic function where the >>sentinel is some constant other than NULL, as long as the value of the >>constant can be determined at compile time and supplied as a parameter >>to the sentinel attribute. > > Does this really occur frequently enough to be worth the trouble? Can > you name a few libraries that do this?
The particular case which prompted this bug report was a parsing engine, which uses a variadic function to construct grammar rules consisting of a start state, a character, a next state, and a list of actions, terminated by the action LastAction (an enum constant equal to -1). Predefined actions are negative numbers to avoid conflict with user-defined actions which are positive numbers; starting user-defined states at 0 rather than 1 allows the user to simply declare the states in an enum (enum { ThisAction, ThatAction, ... } Actions;), without the additional gotcha of having to set the first item to 1 to avoid conflict with an arbitrarily-valued 0 sentinel. I just finished finding an extremely non-obvious bug in which one particular rule in a long list of rules was not terminated by LastAction. I was able to find it with valgrind at runtime, but this is exactly the kind of thing that could be caught at compile time by the sentinel check. The original mail to the gcc list about implementation of the sentinel attribute suggested that the ability to specify a different sentinel value could be useful and could be added later after the initial implementation was in place. - Josh Triplett
signature.asc
Description: OpenPGP digital signature