Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > GCC warnings for comma operator

Reply
Thread Tools

GCC warnings for comma operator

 
 
James Kuyper
Guest
Posts: n/a
 
      04-11-2013
On 04/11/2013 01:23 PM, W Karas wrote:
> On Thursday, April 11, 2013 8:16:10 AM UTC-4, James Kuyper wrote:
>> On 04/10/2013 07:07 PM, W Karas wrote:
>>> Recently I wrote a macro to set a bit field at an arbitrary location
>>> in an array of some unsigned integral type. (Can't show it because
>>> it's proprietary.) The bit field is specified as a bit offset from
>>> the start of the array, and the number of bits of width. Probably a
>>> mistake, but I decided it would (somehow) be more aesthetic if the
>>> macro expanded to an expression with side effects (and useless value)
>>> rather than a (compound) statement. ...

>>
>>
>>
>> I agree - that was probably a mistake.

>
> Then again, when there are 'if' statements within macros, and the condition of the 'if' is a constant that can be evaluated at compile time, you can get "unreachable code" warnings.


Again, that's something you could probably avoid using an inline
function rather than a macro. Depending upon the details of the macro
(which you haven't given us), if it were converted into an inline
function, the compiler might not even put "constant expression" together
with "if()" until after it's inlined the code, at which point you're
unlikely to get that particular warning.
--
James Kuyper
 
Reply With Quote
 
 
 
 
W Karas
Guest
Posts: n/a
 
      04-11-2013
On Thursday, April 11, 2013 1:42:56 PM UTC-4, James Kuyper wrote:
> On 04/11/2013 01:23 PM, W Karas wrote:
>
> > On Thursday, April 11, 2013 8:16:10 AM UTC-4, James Kuyper wrote:

>
> >> On 04/10/2013 07:07 PM, W Karas wrote:

>
> >>> Recently I wrote a macro to set a bit field at an arbitrary location

>
> >>> in an array of some unsigned integral type. (Can't show it because

>
> >>> it's proprietary.) The bit field is specified as a bit offset from

>
> >>> the start of the array, and the number of bits of width. Probably a

>
> >>> mistake, but I decided it would (somehow) be more aesthetic if the

>
> >>> macro expanded to an expression with side effects (and useless value)

>
> >>> rather than a (compound) statement. ...

>
> >>

>
> >>

>
> >>

>
> >> I agree - that was probably a mistake.

>
> >

>
> > Then again, when there are 'if' statements within macros, and the condition of the 'if' is a constant that can be evaluated at compile time, you can get "unreachable code" warnings.

>
>
>
> Again, that's something you could probably avoid using an inline
>
> function rather than a macro. Depending upon the details of the macro
>
> (which you haven't given us), if it were converted into an inline
>
> function, the compiler might not even put "constant expression" together
>
> with "if()" until after it's inlined the code, at which point you're
>
> unlikely to get that particular warning.
>
> --
>
> James Kuyper


Can't show the actual code, it's proprietary work stuff.

With the compilers we use (GCC, Green Hills) I've been very disappointed with how they handle nested inline functions.
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      04-11-2013
On Thu, 2013-04-11, W Karas wrote:
....
> With the compilers we use (GCC, Green Hills) I've been very
> disappointed with how they handle nested inline functions.


Recent or very old gcc? I'd expect a recent one to be good at
inlining, because it's a C feature that's used a lot these days, and
because it's even /more/ used in the C++ half of gcc.

I'm also asking because I know from experience that in the embedded
space you often find yourself locked to outdated tools.

Of course I'm biased: I use gcc a lot, and while I do it on "embedded"
systems, these systems have powerful CPUs belonging to well-known and
well-supported families.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Ike Naar
Guest
Posts: n/a
 
      04-11-2013
On 2013-04-11, W Karas <(E-Mail Removed)> wrote:
> Can't show the actual code, it's proprietary work stuff.


Then ask for help at work.
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      04-11-2013
W Karas <(E-Mail Removed)> writes:

> Recently I wrote a macro to set a bit field at an arbitrary
> location in an array of some unsigned integral type. (Can't show
> it because it's proprietary.) The bit field is specified as a bit
> offset from the start of the array, and the number of bits of
> width. Probably a mistake, but I decided it would (somehow) be
> more aesthetic if the macro expanded to an expression with side
> effects (and useless value) rather than a (compound) statement.
> The expanded macro has multiple instances of this pattern:
>
> yada-yada , (exprA ? exprB : 0), yada-yada
>
> where exprB has side effects. GCC seems to have no complaints as
> long as exprB evaluates to a constant value known at compile time.
> But if exprB has a variable in it, and exprA is false, GCC gives a
> "value not used in comma expression" warning (using -Wall) or
> something like that. The -Wno-unused-value option eliminates this
> warning. I would like to ask 2 questions.
>
> 1) What are some problems I might miss by using -Wno-unused-value
> ? I thought it might disable the warning for unused variables,
> but that is separate and covered by -Wunused-variables.
>
> 2) Is there a more targeted way to eliminate this spurious
> warning? I'd hate to have to put pragmas every place I invoked
> the macro.


Did you read the gcc man page? The one I looked at explains
what to do in the code to inhibit the warning for a specific
instance.
 
Reply With Quote
 
Edward A. Falk
Guest
Posts: n/a
 
      04-12-2013
In article <(E-Mail Removed)>,
Jorgen Grahn <(E-Mail Removed)> wrote:

>I'm also asking because I know from experience that in the embedded
>space you often find yourself locked to outdated tools.


Testify, brother! Working in C++ right now, with no STL.

--
-Ed Falk, http://www.velocityreviews.com/forums/(E-Mail Removed)
http://thespamdiaries.blogspot.com/
 
Reply With Quote
 
Noob
Guest
Posts: n/a
 
      04-12-2013
W Karas wrote:

> Can't show the actual code, it's proprietary work stuff.


Can you comment on the specs in my direct reply to you?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Warnings with gcc thibault.langlois@di.fc.ul.pt C Programming 34 11-25-2005 10:58 AM
comma operator and assignment operator G Patel C Programming 4 02-08-2005 02:53 AM
use warnings; and use Warnings; give different results Ted Sung Perl Misc 1 08-30-2004 10:22 PM
Removing GCC compiler warnings from fabsf(), sqrtf()... Charlie Zender C Programming 8 01-04-2004 01:11 AM
Vexing GCC warnings: "assignment discards qualifiers from pointertarget type" Charlie Zender C Programming 12 01-03-2004 12:18 AM



Advertisments