delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/01/22/05:42:45

X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <20070121143731 DOT GC25379 AT ns1 DOT anodized DOT com> <009401c73d79$4cf91d40$a501a8c0 AT CAM DOT ARTIMI DOT COM> <loom DOT 20070122T085309-902 AT post DOT gmane DOT org>
Subject: RE: cygwin source question
Date: Mon, 22 Jan 2007 10:42:19 -0000
Message-ID: <00b401c73e11$fdc39d10$a501a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <loom.20070122T085309-902@post.gmane.org>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 22 January 2007 08:19, Yitzchak Scott-Thoennes wrote:

> 
> Some people prefer (expr) ? 1 : 0, which looks a lot worse to me than
> !!(expr). 
> 

  Compiles to the exact same thing at -O0 and at -O2, as it happens...

/tmp $ gcc -x c -S -o - -

int foo (int argc)
{
  return (argc == 23) ? 1 : 0;
}

int bar (int argc)
{
  return !!(argc == 23);
}

        .file   ""
        .text
.globl _foo
        .def    _foo;   .scl    2;      .type   32;     .endef
_foo:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        sete    %al
        movzbl  %al, %eax
        popl    %ebp
        ret
.globl _bar
        .def    _bar;   .scl    2;      .type   32;     .endef
_bar:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        sete    %al
        movzbl  %al, %eax
        popl    %ebp
        ret
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/tmp $ gcc -O0 -x c -S -o - -

int foo (int argc)
{
  return (argc == 23) ? 1 : 0;
}

int bar (int argc)
{
  return !!(argc == 23);
}

        .file   ""
        .text
.globl _foo
        .def    _foo;   .scl    2;      .type   32;     .endef
_foo:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        sete    %al
        movzbl  %al, %eax
        popl    %ebp
        ret
.globl _bar
        .def    _bar;   .scl    2;      .type   32;     .endef
_bar:
        pushl   %ebp
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        sete    %al
        movzbl  %al, %eax
        popl    %ebp
        ret
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/tmp $ gcc -O2 -x c -S -o - -

int foo (int argc)
{
  return (argc == 23) ? 1 : 0;
}

int bar (int argc)
{
  return !!(argc == 23);
}

        .file   ""
        .text
        .p2align 4,,15
.globl _foo
        .def    _foo;   .scl    2;      .type   32;     .endef
_foo:
        pushl   %ebp
        xorl    %eax, %eax
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        popl    %ebp
        sete    %al
        ret
        .p2align 4,,15
.globl _bar
        .def    _bar;   .scl    2;      .type   32;     .endef
_bar:
        pushl   %ebp
        xorl    %eax, %eax
        movl    %esp, %ebp
        cmpl    $23, 8(%ebp)
        popl    %ebp
        sete    %al
        ret
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/tmp $


  ... so no reason not to choose whichever you like the best.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019