From owner-freebsd-hackers Fri Aug 21 19:07:53 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id TAA06781 for freebsd-hackers-outgoing; Fri, 21 Aug 1998 19:07:53 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from dingo.cdrom.com (ppp-d3.dialup.hilink.com.au [203.2.144.13]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA06767 for ; Fri, 21 Aug 1998 19:07:43 -0700 (PDT) (envelope-from mike@dingo.cdrom.com) Received: from dingo.cdrom.com (localhost [127.0.0.1]) by dingo.cdrom.com (8.9.1/8.8.8) with ESMTP id TAA11658; Fri, 21 Aug 1998 19:05:18 GMT (envelope-from mike@dingo.cdrom.com) Message-Id: <199808211905.TAA11658@dingo.cdrom.com> X-Mailer: exmh version 2.0.2 2/24/98 To: Phil Gilley cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Stupidity or compiler bug? In-reply-to: Your message of "Fri, 21 Aug 1998 20:50:37 EST." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 21 Aug 1998 19:05:17 +0000 From: Mike Smith Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Am I doing something really stupid here or is this a compiler bug? > The output of this program under 2.2.7-RELEASE is "1.2.3.4 1.2.3.4" > which isn't what I was expecting. "1.2.3.4 5.6.7.8" is what I was > hoping for. > > #include > #include > #include > #include > #include > > void main() { > struct ip iph; > > iph.ip_src.s_addr = ntohl(0x01020304); > iph.ip_dst.s_addr = ntohl(0x05060708); > > printf("%s %s\n", inet_ntoa(iph.ip_src), inet_ntoa(iph.ip_dst)); > } inet_ntoa returns a pointer to a static buffer. gcc is evaluating arguments right to left (ie. in stacking order), so the ip_src call is made last, but the pointer is the same in both cases. Try: printf("%s ", inet_ntoa(iph.ip_src)); printf("%s\n", inet_ntoa(iph.ip_dst)); or use strdup() if your real intent is to pass the strings around. -- \\ Sometimes you're ahead, \\ Mike Smith \\ sometimes you're behind. \\ mike@smith.net.au \\ The race is long, and in the \\ msmith@freebsd.org \\ end it's only with yourself. \\ msmith@cdrom.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message