From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Warning control. Is there more convenient way? Date: Wed, 15 Oct 1997 09:07:06 -0700 Organization: Alcyone Systems Lines: 75 Message-ID: <3444EA2A.43F7DE1F@alcyone.com> References: NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Roman Suzi wrote: > What can I add to suppress them in GCC, so that > - I shall not receive another kind of warning; > - the effectiveness of the code will remain the > same (no additional commands will be inserted for dummy > usage of the variables) ? You have three options: First, if you're using C++ (you mentioned both C and C++), then you can leave off the argument name, viz. int f(void *a, int b, double /* unused */) { ... } In both languages, you can use them in a dummy expression which has no effect: int f(void *a, int b, double unused) { (void) unused; ... } This creates an extra statement, but a good compiler (and I'm sure gcc qualifies, though I haven't actually checked myself) will optimize it out, leaving you with no extra code. Though this might cause the compiler to emit "code has no effect" warnings. A final, less ideal option, is simply to name the argument `unused'. That way you can look at the warnings emitted at a glance and decide whether or not they're ones you didn't anticipate or not. > I think the author of DJGPP can easily include > along INCLUDE warning checkboxes the EXCLUDE > warning ones: so it will be much easier to > check just 'Wall' and a few of unwanted warnings. See the Warning Options node of the info gcc page, where it lists each warning and what command-line option to provide to remove it. (I am guessing you're using RHIDE, or somesuch, since DJGPP doesn't have "checkboxes.") Specifically: `-Wunused' Warn whenever a variable is unused aside from its declaration, whenever a function is declared static but never defined, whenever a label is declared but not used, and whenever a statement computes a result that is explicitly not used. To suppress this warning for an expression, simply cast it to void. For unused variables and parameters, use the `unused' attribute (*note Variable Attributes::.). Note, however, that this doesn't address _your_ problem, because you want _some_ of the unused argument warnings to be suppressed, but others to be emitted. > Or are there any #pragma s to do the trick? There may be, though in my quick scan through the info pages I couldn't find any. The gcc maintainers tend to frown upon #pragmas, so they're usually only provided for fairly limited circumstances. -- Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com Alcyone Systems / http://newton.alcyone.com/ San Jose, California, United States / icbm://+37.20.07/-121.53.38 \ "After each war there is a little / less democracy to save." / Brooks Atkinson