From owner-freebsd-hackers Fri May 30 09:50:44 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id JAA24864 for hackers-outgoing; Fri, 30 May 1997 09:50:44 -0700 (PDT) Received: from dg-rtp.dg.com (dg-rtp.rtp.dg.com [128.222.1.2]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id JAA24854 for ; Fri, 30 May 1997 09:50:38 -0700 (PDT) Received: by dg-rtp.dg.com (5.4R3.10/dg-rtp-v02) id AA04910; Fri, 30 May 1997 12:50:04 -0400 Received: from ponds by dg-rtp.dg.com.rtp.dg.com; Fri, 30 May 1997 12:50 EDT Received: from lakes.water.net (lakes [10.0.0.3]) by ponds.water.net (8.8.5/8.7.3) with ESMTP id HAA14579; Fri, 30 May 1997 07:52:43 -0400 (EDT) Received: (from rivers@localhost) by lakes.water.net (8.8.5/8.6.9) id IAA11334; Fri, 30 May 1997 08:00:17 -0400 (EDT) Date: Fri, 30 May 1997 08:00:17 -0400 (EDT) From: Thomas David Rivers Message-Id: <199705301200.IAA11334@lakes.water.net> To: ponds!FreeBSD.ORG!hackers, ponds!anchorage.net!un_x Subject: Re: cc/gcc Content-Type: text Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > > > with cc/gcc, i get outputs of "1" and "0" respectively. why? > is this construct ABSOLUTELY incorrect, or is something else amuck? > /*****************************************************************************/ > #include "stdio.h" > /*****************************************************************************/ > void main (unsigned char argc, unsigned char **argv) { > > unsigned char a, b, c; > > a = 1; b = 1; c = 0; > c = a == b == 1 ? 1 : 0 ; printf(" %i\n", c); > a='1'; b='1'; c = 0; > c = a == b == '1' ? '1' : '0'; printf(" %c\n", c); > > exit( 0 );} > /*****************************************************************************/ > > I believe '?' has a higher precedence than '=='; so you are really saying: is b equal to: if 1 then 1 else 0 compare b and 1 - they are the same. -> yes is a equal b? compare a with the result of b's compare (1 == 1)? -> yes assign the 'yes' to c. c <= 1 Then, in the second case: > c = a == b == '1' ? '1' : '0'; printf(" %c\n", c); is b equal to: if 0x31 then 0x31 else 0x30 compare b and 0x31 - they are the same. is a iequal to 1 (the result of the b == ..) -> no ('a' is 0x31, the result of the boolean is 1) c is assigned the result of the comparison with a and 1 c <= 0 So, c gets the value 0 in the second case. Does that help? - Dave Rivers -