🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
6 messages
6 total messages Started by Chuck Kirschman Tue, 05 Mar 1996 01:14
What does this do?
#7934
Author: Chuck Kirschman
Date: Tue, 05 Mar 1996 01:14
25 lines
1068 bytes
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?

thanks
chuck

---
Chuck Kirschman                     ckirsch@eng.clemson.edu
http://www.eng.clemson.edu/~ckirsch/
"I don't NEED to compromise my principles, because they don't have the
 slightest bearing on what happens to me anyway." - Calvin
Re: What does this do?
#7936
Author: Dik T. Winter
Date: Fri, 08 Mar 1996 01:43
21 lines
939 bytes
In article <4hg4hv$iqb@hubcap.clemson.edu> ckirsch@eng.clemson.edu writes:
 > void foo(int bar, float *baz)
 > {
 >   int x,y;
 >   (void) x;
 >   (void) y;
...
 > The compiler (Watcom 10.5) doesn't like it, but lets it pass.

I would not like it either.

 > What exactly is this doing?

Nothing.

 > And, more importantly, what is the author trying to acheive?

Creating lines of code out of thin air.
-- 
dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland, +31205924098
home: bovenover 215, 1025 jn  amsterdam, nederland; http://www.cwi.nl/~dik/
Re: What does this do?
#7935
Author: Matthew Kirkwood
Date: Fri, 08 Mar 1996 01:44
32 lines
1609 bytes
On 5 Mar 1996, Chuck Kirschman 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?

I'm not entirely sure, but I would guess that what he's trying to do is 
make the compiler know that x and y have been referenced by just 
evaulating them and ignoring the result.  I've no idea why he'd want to 
do this, except to disable 'Unreferenced local...' warnings, but then if 
the compiler complains at this, then it makes it seem entirely pointless.

Odd...

--
Matthew Kirkwood      |  Mail:  matthew.kirkwood@lmh.ox.ac.uk
LMH JCR,              |    or:  m95mtk@ecs.ox.ac.uk
Oxford OX2 6QA,       |  "There are no coincidences,
England.              |     But sometimes the pattern is more obvious."
Re: What does this do?
#7937
Author: Alexander J Russell
Date: Fri, 08 Mar 1996 07:13
37 lines
1550 bytes
In article <4hg4hv$iqb@hubcap.clemson.edu>, ckirsch@eng.clemson.edu says...
>
>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;
>  
these two line appear to do nothing. It looks like it is casting x & y to void 
data type, but not doing anything with it.
>  (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?
>
>thanks
>chuck
>
>---
>Chuck Kirschman                     ckirsch@eng.clemson.edu
>http://www.eng.clemson.edu/~ckirsch/
>"I don't NEED to compromise my principles, because they don't have the
> slightest bearing on what happens to me anyway." - Calvin
>
>

-- 
The AnArChIsT! Anarchy! Not Chaos!
aka
Alex Russell
alexad3@iceonline.com
Re: What does this do?
#7938
Author: 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.
-- 
Re: What does this do?
#7941
Author: Scott Fluhrer
Date: Sun, 10 Mar 1996 02:47
49 lines
2085 bytes
In <4hg4hv$iqb@hubcap.clemson.edu> ckirsch@eng.clemson.edu (Chuck
Kirschman) writes: 
>
>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]
>}
>
>What is the author trying to acheive?
Of the top, I can think of two plausible scenarios which could acount
for this:

Scenario 1:

    - The programmer originally wrote function using the variables x
and y
    - The programmer later rewrote the function, removing the
references to x and y, but not their declarations
    - The programmer later went through getting rid of the compiler
warnings.  Whenever if saw a 'unused variable' warning, he mindlessly
stuck in a dummy line to get rid of the warning, resulting in the
present code

    If this is the case, you can safely ignore them, or delete them.

Scenario 2 (don't read this unless you have a strong stomache):

    The programmer is playing games with the stack space.  That is, he
figured out how stack space was allocated on his particular compiler,
and he happened to require 2 int's worth of space.  Why he did this
travesty on portability and all common sense, rather that doing
something like explicitly allocating the space he required, I have no
idea.  To see if he is doing this, look through the [rest of function]
code to see if he takes the address of an auto or a parameter, and does
arithmetic on the resulting pointer.  If so, well, you just hit one of
the top coding nightmares :-(
>
>thanks
>chuck
poncho
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads