troubleshooting Question

Suppressing a warning from gcc/g++

Avatar of ewajoz
ewajoz asked on
Linux OS Dev
12 Comments1 Solution1741 ViewsLast Modified:

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,


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros