Link to home
Start Free TrialLog in
Avatar of ewajoz
ewajoz

asked on

Suppressing a warning from gcc/g++

Hello

This is a repetition of a question that I posted to the general "Programing" topic and did not get a nice solution.

I would like to know if there is a way of disabling a specific warning in gcc. Normally I would do it with the preprocessor pragma, but cannot find the way of getting warning numbers. I neither can use a gcc option as it seems that none is suitable for my case.

The problem is that when one performs >=0 check against and unsigned short (but not unsigned int for example!) the gcc issues the warning:
"comparison is always 1 due to limited range of data type".
According to the manual it should only be displayed if you use -W option, but for unsigned short it is always displayed (of course unless using -w).

I cannot change the comparison itself, as it is inside the template - so it only for some instantiations when this comparison is always true. The warnings are quite annoying for template users.
I include a few lines of code with which you can check this behaviour.

Thanks a lot for your help,

Ewa
Avatar of daryllee
daryllee

Your question said you "included a few lines" but you don't.  Perhaps you could do so.  And if the template is not part of the STL, perhaps you could include it, or a substitute that reproduces the problem.

In the meantime, who owns the template?  Is it part of the STL?  Perhaps the template writer could be a little smarter.
Avatar of ewajoz

ASKER

Sorry, here's the code (the warning is only generated by the first comparison). The code in the template is analoguos.

int main()
{
unsigned short i;
if (i >= 0)
   ;
unsigned int j;
if (j >= 0)
   ;
return 0;
}

The template is not an STL one.

The owner of the template is some other person and possible changes to the implementation can have very limited scope only. That's why I do not to present the template itself here. Just want to know how can I avoid this warning in the presented piece of code (One trick is splitting it to two comparisons (== and >), which helps but is not too elegant solution)
Is there a way of using #pragma warning (disable)?.

I do not know if the template writer could be a little smarter, he looks quite smart enough :-).



Ewa

ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Your question said you "included a few lines" but you don't.  Perhaps you could do so.  And if the template is not part of the STL, perhaps you could include it, or a substitute that reproduces the problem.

In the meantime, who owns the template?  Is it part of the STL?  Perhaps the template writer could be a little smarter.
ix the include according gcc (man-page)'s recomendation
Will be a short fix.
Avatar of ewajoz

ASKER

Obviously, I've studied the gcc man page, especially the warning options. The only adequate one I've found is -W (extra warnings) that will make a warning dislplayed when "An unsigned value is compared against zero with `<' or `<='", but I do not use this option and as you noticed this is not my case.

So would you please indicate what fix exactly do you mean. Sorry, if I am not perceptive enough.

Ewa
fix the include which uses the wrong 0 check. Even if it is not your code, you have the include (or source) and my change it safely there.
I don't think you can use the
#pragma warning (disable:#)  this is for win_32 only, As far as I know.
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in approximately one week.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
https://www.experts-exchange.com/help.jsp#hs5

jmcg
EE Cleanup Volunteer
Since it's not apparent to me that a resolution was reached, I'd favor a Delete action on this question. If Ewajoz were to come back and explain that he (she?) came up with a solution and posted it here, that recommendation would become PAQ/Refund.
hmm, probably this problem does not longer apply to modern gcc (no, Ihavn't and I won't check it), but for the older gcc (up to 2.95.x) my explanaition is correct
and I gave a suggestion too (which worked at least for me, in the described context)
So I don't see a reason for a delete and/or refund 'cause there is a solution.
Agreed, jmcg, ewajoz?
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: ahoffmann {http:#7264359}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer