Static code analysis
Re: Static code analysis
Not an another argument, please? There is another solution, I'm giving it. That's all.
Last edited by qw on Mon Mar 26, 2012 12:58 am, edited 1 time in total.
Re: Static code analysis
No, not an argument. Sorry if I didn't make that clear - there has to be some difference involved with this syntax, some advantage or somesuch (or the GCC people wouldn't have bothered with it), and I'd like to know about it.
Every good solution is obvious once you've found it.
Re: Static code analysis
Well, personally, I never liked the "do { } while (0)" because it was not intended to be used that way. It does not show what it is supposed to do, and it confuses people who are unfamiliar with the C preprocessor, even if they are experienced in other structured programming languages. And it can't return a value. I think the GCC solution is much more elegant.
After second thought, an inline function is probably the most elegant solution, and standard conforming too.
After second thought, an inline function is probably the most elegant solution, and standard conforming too.
Re: Static code analysis
This gcc extension is which makes it possible to treat a statement as an expression. Which is an additional functionality not available in theSolar wrote:No, not an argument. Sorry if I didn't make that clear - there has to be some difference involved with this syntax, some advantage or somesuch (or the GCC people wouldn't have bothered with it), and I'd like to know about it.
Code: Select all
do { ... } while(0)
Code: Select all
({ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; })
More info here: http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
Re: Static code analysis
I got a false V595 in PVS Studio from the following:
Code: Select all
if(SomeFunction(p)) {
SomeOtherFunction(p->data);
}
if(p) {