Page 3 of 3
Re: Static code analysis
Posted: Mon Mar 26, 2012 12:56 am
by qw
Not an another argument, please? There is another solution, I'm giving it. That's all.
Re: Static code analysis
Posted: Mon Mar 26, 2012 12:58 am
by Solar
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.
Re: Static code analysis
Posted: Mon Mar 26, 2012 1:01 am
by qw
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.
Re: Static code analysis
Posted: Mon Mar 26, 2012 10:27 am
by Snake
Solar 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.
This gcc extension is which makes it possible to treat a statement as an expression. Which is an additional functionality not available in the
You can do things like:
Code: Select all
({ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; })
Which will evaluate to the absolute value of foo. In contrast the do/while loop does not evaluate to anything.
More info here:
http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
Re: Static code analysis
Posted: Mon Mar 26, 2012 11:52 am
by Gigasoft
I got a false V595 in PVS Studio from the following:
Code: Select all
if(SomeFunction(p)) {
SomeOtherFunction(p->data);
}
if(p) {