9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] what's wrong with this?
@ 2002-09-27 14:05 Russ Cox
  0 siblings, 0 replies; 10+ messages in thread
From: Russ Cox @ 2002-09-27 14:05 UTC (permalink / raw)
  To: 9fans

The problem is that assert tries to include the
text of what is being asserted, since the compiler
doesn't provide preprocessor variables for the
current file and line number.

Russ


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [9fans] what's wrong with this?
@ 2002-09-27 14:09 Sape Mullender
  2002-10-07 13:53 ` peter a. cejchan
  0 siblings, 1 reply; 10+ messages in thread
From: Sape Mullender @ 2002-09-27 14:09 UTC (permalink / raw)
  To: 9fans

> Dear friends,
>
> 8c complies "syntax error" when the following macro is called:
>
> #define	jpc_bitstream_getbit_macro(bitstream) \
> 	(assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
> 	  (--(bitstream)->cnt_ >= 0) ? \
> 	  (((bitstream)->buf_ >> (bitstream)->cnt_) & 1) : \
> 	  jpc_bitstream_fillbuf(bitstream))
>
> int ret;
> ...
> ret=jpc_bitstream_getbit_macro(bitstream);

For starters, it's abhorrently awful code.  You're also using macros recursively.
Assert is a macro:
	#define	assert(x) if(x){}else _assert("x")
Substitute it in your code and behold the mess you get.

What are you trying to save with this macro anyway?

	Sape



^ permalink raw reply	[flat|nested] 10+ messages in thread
* [9fans] what's wrong with this?
@ 2002-09-27 14:12 Peter A. Cejchan
  0 siblings, 0 replies; 10+ messages in thread
From: Peter A. Cejchan @ 2002-09-27 14:12 UTC (permalink / raw)
  To: 9fans

Dear friends,

8c complies "syntax error" when the following macro is called:

#define	jpc_bitstream_getbit_macro(bitstream) \
	(assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
	  (--(bitstream)->cnt_ >= 0) ? \
	  (((bitstream)->buf_ >> (bitstream)->cnt_) & 1) : \
	  jpc_bitstream_fillbuf(bitstream))

int ret;
...
ret=jpc_bitstream_getbit_macro(bitstream);


TIA4help,
--
++pac.

Peter A. Cejchan
Paleobiology Lab, GLU Acad. Sci. CZ
<pac@next.gli.cas.cz>
[http | ftp]://next.gli.cas.cz


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [9fans] what's wrong with this?
@ 2002-09-27 14:28 Charles Forsyth
  2002-09-30  9:17 ` Douglas A. Gwyn
  2002-09-30  9:28 ` Ralph Corderoy
  0 siblings, 2 replies; 10+ messages in thread
From: Charles Forsyth @ 2002-09-27 14:28 UTC (permalink / raw)
  To: 9fans

i was wondering whether the C assert macro was regarded as
an expression or a statement, but as usual my C book isn't
nearby.


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [9fans] what's wrong with this?
@ 2002-09-27 15:36 rog
  2002-09-30  9:18 ` Douglas A. Gwyn
  0 siblings, 1 reply; 10+ messages in thread
From: rog @ 2002-09-27 15:36 UTC (permalink / raw)
  To: 9fans

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

i always thought that:

#define	assert(x)	if(x){}else _assert("x")

was a bit dodgy... it's a good thing macros aren't
used much in plan 9 otherwise someone would
have been bitten.

still it's better than the ## nastiness, i suppose.

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

From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] what's wrong with this?
Date: Fri, 27 Sep 2002 10:05:43 -0400
Message-ID: <b70f510fee137a3d8569f447c6f762e3@plan9.bell-labs.com>

The problem is that assert tries to include the
text of what is being asserted, since the compiler
doesn't provide preprocessor variables for the
current file and line number.

Russ

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [9fans] what's wrong with this?
@ 2002-10-07 14:34 Russ Cox
  0 siblings, 0 replies; 10+ messages in thread
From: Russ Cox @ 2002-10-07 14:34 UTC (permalink / raw)
  To: 9fans

the correct workaround is

#define assert(x) ((x) ? 0 : (_assert("x"), 0))



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

end of thread, other threads:[~2002-10-07 14:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-27 14:05 [9fans] what's wrong with this? Russ Cox
2002-09-27 14:09 Sape Mullender
2002-10-07 13:53 ` peter a. cejchan
2002-09-27 14:12 Peter A. Cejchan
2002-09-27 14:28 Charles Forsyth
2002-09-30  9:17 ` Douglas A. Gwyn
2002-09-30  9:28 ` Ralph Corderoy
2002-09-27 15:36 rog
2002-09-30  9:18 ` Douglas A. Gwyn
2002-10-07 14:34 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).