From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 1237 invoked from network); 24 Oct 1999 03:01:02 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 24 Oct 1999 03:01:02 -0000 Received: from mail4.nycap.rr.com (mail4-1.nyroc.rr.com [24.92.33.20]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id XAA21619 for ; Sat, 23 Oct 1999 23:01:01 -0400 Received: from cm-24-92-59-49.nycap.rr.com ([24.92.59.49]) by mail4.nycap.rr.com (Post.Office MTA v3.5.3 release 223 ID# 0-59787U250000L250000S0V35) with ESMTP id com for ; Sat, 23 Oct 1999 23:02:39 -0400 Date: Sat, 23 Oct 1999 23:03:17 -0400 (EDT) From: Dan Morrill Sender: morrildl@obsequious.yi.org To: axp-list@redhat.com Subject: Function parameter weirdness Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII -----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-----