Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Dan Morrill <morrildl@nycap.rr.com>
To: axp-list@redhat.com
Subject: Function parameter weirdness
Date: Sat, 23 Oct 1999 23:03:17 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.10.9910232237150.13997-100000@obsequious.yi.org> (raw)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Okay, here's a weird one for the gurii.  I am attempting to get the JavaComm
package working with UG's JDK 1.1.8.  The JavaCOMM API requires that you have
a native JNI driver for your platform;  the one for Linux is called
RXTX (at http://www.frii.com/~jarvi/rxtx/ ).

In one of the RXTX source files is the following rather simple function;
basically it maps integers to constants from a header file.  (The stuff in
/* DEBUG CODE */ ... /* END DEBUG CODE */ is my stuff, and is not in the
original source.)

**********************************
int translate_speed( JNIEnv *env, jint speed )
{
/* DEBUG CODE */
fprintf( stderr, "speed: %d\n", speed );
if (speed == 9600) {
    fprintf( stderr, "hit\n" );
}
fprintf( stderr, "b-and: %d\n", (9600 & speed) );
fprintf( stderr, "b-or: %d\n", (9600 | speed) );
/* END DEBUG CODE */
	switch( speed ) {
		case 0:		return B0;
		case 50:		return B50;
		case 75:		return B75;
		case 110:	return B110;
		case 134:	return B134;
		case 150:	return B150;
		case 200:	return B200;
		case 300:	return B300;
		case 600:	return B600;
		case 1200:	return B1200;
		case 1800:	return B1800;
		case 2400:	return B2400;
		case 4800:	return B4800;
		case 9600:	return B9600;
		case 19200:	return B19200;
		case 38400:	return B38400;
		case 57600:	return B57600;
		case 115200:	return B115200;
		case 230400:	return B230400;
#ifdef B460800
		case 460800:	return B460800;
#endif
/* DEBUG CODE */
		default:	fprintf( stderr, "wtf? %d\n", speed );
/* END DEBUG CODE */
	}

/* DEBUG CODE */
fprintf( stderr, "speed2: %d\n", speed );
/* END DEBUG CODE */
	throw_java_exception( env, UNSUPPORTED_COMM_OPERATION,
		"translate_speed", "speed" );
	return 0;
}
**********************************


"jint" is typedef'ed to "int" upstream in the JNI headers.  If you run one of
the sample test programs provided with the JavaComm package and tell it to
set the baud rate to 9600, you get the following output from my debug
statements:



speed: 9600
b-and: 9600
b-or: 9600
wtf? 9600
speed2: 9600 


So:  speed is a 32-bit int with the value of 9600, and is binary identical
to the constant 9600 (as shown by the & and | ).  However, speed != 9600
(since it fails both the switch and my if statement.)

Eh?


I don't know whether to blame some the compiler (egcs 1.1.2), glibc (2.1.1),
or JNI, or even myself (if this is normal.)

It gets better though.  If I change the switch (speed) to:

switch( speed | speed ) {
...
}

...it still fails to work.  If I do this, however:

fprintf( stderr, "%d", speed );
switch( speed | speed ) {
...
}

...it works!

Anyone have any ideas?  This has got me mightily flummoxed.


My machine is an SX164; kernel 2.2.12.  More info available upon request.


Thanks,

Dan Morrill
Computer Scientist, Physicist
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE4Enb6U6LPdJTKfTwRAid/AJ95OZM2CERcA7nGs+oH+EoRK/2cCgCfWYoe
liTmmZIDbcrrTnR/n7NM0oo=
=mi7/
-----END PGP SIGNATURE-----


             reply	other threads:[~1999-10-24  3:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-24  3:03 Dan Morrill [this message]
1999-10-24 15:03 ` Function parameter weirdness Uncle George
1999-10-24 20:18   ` Dan Morrill
1999-10-25 10:19     ` Uncle George
1999-10-28 23:38       ` Richard Henderson
1999-10-29 10:28         ` Uncle George
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox