9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] USED() macro
@ 2005-11-12 10:00 李微
  2005-11-12 11:18 ` Charles Forsyth
  0 siblings, 1 reply; 5+ messages in thread
From: 李微 @ 2005-11-12 10:00 UTC (permalink / raw)
  To: 9fans

In plan9port, USED() is defined as

        #define USED(x) if(x){}else{}

Does it mean that USED() can only be applied on variables of "scalar
types"? But r is of a struct type in

        void
        drawresizewindow(Rectangle r)
        {
        	USED(r);
        	
        	bad();
        }

in $PLAN9/src/libdraw/nowsys-wsys.c.

When compiling, 9c complains on that. A bug? Or an extension of Plan 9's
C dialect?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] USED() macro
  2005-11-12 10:00 [9fans] USED() macro 李微
@ 2005-11-12 11:18 ` Charles Forsyth
  2005-11-12 13:17   ` Russ Cox
  0 siblings, 1 reply; 5+ messages in thread
From: Charles Forsyth @ 2005-11-12 11:18 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 79 bytes --]

perhaps it could use if(&x) instead of if(x)
to cope with structures as well

[-- Attachment #2: Type: message/rfc822, Size: 2904 bytes --]

From: 李微 <leethium@163.com>
To: 9fans <9fans@cse.psu.edu>
Subject: [9fans] USED() macro
Date: Sat, 12 Nov 2005 18:00:36 +0800
Message-ID: <1131789636.7582.55.camel@localhost.localdomain>

In plan9port, USED() is defined as

        #define USED(x) if(x){}else{}

Does it mean that USED() can only be applied on variables of "scalar
types"? But r is of a struct type in

        void
        drawresizewindow(Rectangle r)
        {
        	USED(r);
        	
        	bad();
        }

in $PLAN9/src/libdraw/nowsys-wsys.c.

When compiling, 9c complains on that. A bug? Or an extension of Plan 9's
C dialect?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] USED() macro
  2005-11-12 11:18 ` Charles Forsyth
@ 2005-11-12 13:17   ` Russ Cox
  2005-11-12 14:42     ` 李微
  0 siblings, 1 reply; 5+ messages in thread
From: Russ Cox @ 2005-11-12 13:17 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> Does it mean that USED() can only be applied on variables of "scalar
> types"? But r is of a struct type in

yes.

>
>         void
>         drawresizewindow(Rectangle r)
>         {
>                 USED(r);
>
>                 bad();
>         }
>
> in $PLAN9/src/libdraw/nowsys-wsys.c.
>
> When compiling, 9c complains on that. A bug? Or an extension of Plan 9's
> C dialect?

In Plan 9's C compiler, USED is known to the compiler.
It makes the compiler insert a use of the variable right
there to silence used and not set warnings.

In the ports, it's a clumsy macro trying to have the same
effect.

> perhaps it could use if(&x) instead of if(x)
> to cope with structures as well

I tried this once, but then some (too smart for their
own good) compilers complain that the value is never used.

Russ


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] USED() macro
  2005-11-12 13:17   ` Russ Cox
@ 2005-11-12 14:42     ` 李微
  2005-11-12 16:37       ` Russ Cox
  0 siblings, 1 reply; 5+ messages in thread
From: 李微 @ 2005-11-12 14:42 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> In Plan 9's C compiler, USED is known to the compiler.
> It makes the compiler insert a use of the variable right
> there to silence used and not set warnings.
> 
> In the ports, it's a clumsy macro trying to have the same
> effect.
> 
> > perhaps it could use if(&x) instead of if(x)
> > to cope with structures as well
> 
> I tried this once, but then some (too smart for their
> own good) compilers complain that the value is never used.

Thanks. 

BTW, I'm trying to build plan9port on Ubuntu 5.10. Some problems
encountered:

1) X headers are in /usr/include/X11 only. No 'include' in $X11, not
even a link. So, $PLAN9/src/libdraw/mkwsysrules.sh could not find them;
and set $WSYSTYPE to 'nowsys'. As a result nowsys-*.c get compiled, and
I noticed USED() there.

2) install(1) says:

> If LOCAL.config contains a line WSYS=nowsys then the system is built
> without using X11.

I guess it might be WSYSTYPE=nowsys?

3) 9c uses gcc, but USED() is still defined as if(x){}else{}, not the
version with __attribute__ ((unused)). When I added -D__GNUC__ in 9c, it
complained for redefinition. Why not

        #ifdef __GNUC__
        #	if __GNUC__ >= 3
        #		undef USED
        #		define USED(x) { ulong __y __attribute__ ((unused)); __y =
        (ulong)(x); }
        #	endif
        #endif
        
functioning correctly?

Well, after all, those are all trivial. Few people will set
WSYSTYPE=nowsys.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] USED() macro
  2005-11-12 14:42     ` 李微
@ 2005-11-12 16:37       ` Russ Cox
  0 siblings, 0 replies; 5+ messages in thread
From: Russ Cox @ 2005-11-12 16:37 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> 1) X headers are in /usr/include/X11 only. No 'include' in $X11, not
> even a link. So, $PLAN9/src/libdraw/mkwsysrules.sh could not find them;
> and set $WSYSTYPE to 'nowsys'. As a result nowsys-*.c get compiled, and
> I noticed USED() there.

Fixed.

> 2) install(1) says:
>
> > If LOCAL.config contains a line WSYS=nowsys then the system is built
> > without using X11.
>
> I guess it might be WSYSTYPE=nowsys?

Fixed.

> 3) 9c uses gcc, but USED() is still defined as if(x){}else{}, not the
> version with __attribute__ ((unused)). When I added -D__GNUC__ in 9c, it
> complained for redefinition. Why not
>
>         #ifdef __GNUC__
>         #       if __GNUC__ >= 3
>         #               undef USED
>         #               define USED(x) { ulong __y __attribute__ ((unused)); __y =
>         (ulong)(x); }
>         #       endif
>         #endif
>
> functioning correctly?

It probably is functioning correctly.  You still can't do
    Rectangle r;
    USED(r);
with that definition because you can't cast a Rectangle
to a ulong.  I could change the definition for __GNUC__>=3
but then it would allow non-scalar USED but all the other
platforms would not, so then I'd be getting reports from
the non-gcc users.  I'd rather all the platforms be consistent.

If you're not seeing a warning about the variable never
being used or being set and not used, then it's functioning fine.

Russ


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-12 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-12 10:00 [9fans] USED() macro 李微
2005-11-12 11:18 ` Charles Forsyth
2005-11-12 13:17   ` Russ Cox
2005-11-12 14:42     ` 李微
2005-11-12 16:37       ` Russ Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).