This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: cygwin source question


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]