🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #7938

Re: What does this do?

#7938
From: Kazimir Kylheku
Date: Fri, 08 Mar 1996 17:34
36 lines
1705 bytes
In article <4hg4hv$iqb@hubcap.clemson.edu>,
Chuck Kirschman <ckirsch@eng.clemson.edu> wrote:
 >I'm working in *somebody else's code*, which I'm sure everyone pretty
 >much dreads.  I've run across a construct which I don't understand the
 >purpose of:
 >
 >void foo(int bar, float *baz)
 >{
 >  int x,y;
 >  
 >  (void) x;
 >  (void) y;
 >  
 >  [rest of function]
 >}
 >
 >The compiler (Watcom 10.5) doesn't like it, but lets it pass.  What exactly
 is this doing?  And, more importantly, what is the author trying to acheive?

Those lines do nothing. You may safely remove them.


The only reason for doing something like that would be something like the
following scenario:

Suppose expression E refers to a volatile lvalue which represents a hardware
register. When this register is accessed via a read operation, it causes the
device to do something. The value that is read is not interesting at all.

In that case, you could use (void) E to cause the read, and discard the value.
If E is a volatile lvalue (such as the name of a variable object declared
volatile), the expression will not be optimized away.

In the above example, x and y are simple auto variables that are not volatile,
and certainly don't refer to hardware registers.
-- 
Technical Details
Message-ID: <4hpr2mINN609@keats.ugrad.cs.ubc.ca>
Path: arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mail
References: <4hg4hv$iqb@hubcap.clemson.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mail
From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
Newsgroups: comp.os.msdos.programmer,comp.lang.c
Subject: Re: What does this do?
Date: 8 Mar 1996 09:34:14 -0800
Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
Message-ID: <4hpr2mINN609@keats.ugrad.cs.ubc.ca>
References: <4hg4hv$iqb@hubcap.clemson.edu>
NNTP-Posting-Host: keats.ugrad.cs.ubc.ca