Using explicitly sized variables in functions as auto variables or parameters

Discussion in 'C Programming' started by Adel, Mar 16, 2005.

  1. Adel

    Adel Guest

    Hello.
    Is the statement below proved by the ANSI C standard?
    "It is undesirable to use explicitly sized variables in functions as
    auto variables or parameters. The values will always be stored as the
    processor native word size, and extra code will be generated by the
    compiler to mask off bits that are not significant in the result."

    Adel
     
    Adel, Mar 16, 2005
    #1
    1. Advertising

  2. Adel

    Eric Sosman Guest

    Re: Using explicitly sized variables in functions as auto variablesor parameters

    Adel wrote:
    > Hello.
    > Is the statement below proved by the ANSI C standard?
    > "It is undesirable to use explicitly sized variables in functions as
    > auto variables or parameters. The values will always be stored as the
    > processor native word size, and extra code will be generated by the
    > compiler to mask off bits that are not significant in the result."


    If by "explicitly sized variable" you mean types like
    int8_t or uint_least32_t, then no: The Standard describes
    how these types must behave, but does not specify how the
    implementation produces the behavior. In particular, it
    does not specify that extra code will be generated, nor
    that the values will be stored in a "native" word size.

    If by "explicitly sized variable" you mean something
    else, I need you to explain it to me.

    Advice: Use things like int_fast16_t when your program
    needs the services they provide, and don't fret about micro-
    optimizing UNTIL AND UNLESS you have measurements that show
    it to be necessary. "Premature optimization is the root
    of all evil."

    --
     
    Eric Sosman, Mar 16, 2005
    #2
    1. Advertising

  3. Adel

    CBFalconer Guest

    Re: Using explicitly sized variables in functions as auto variablesorparameters

    Eric Sosman wrote:
    > Adel wrote:
    >
    >> Is the statement below proved by the ANSI C standard?
    >> "It is undesirable to use explicitly sized variables in functions as
    >> auto variables or parameters. The values will always be stored as the
    >> processor native word size, and extra code will be generated by the
    >> compiler to mask off bits that are not significant in the result."

    >
    > If by "explicitly sized variable" you mean types like
    > int8_t or uint_least32_t, then no: The Standard describes
    > how these types must behave, but does not specify how the
    > implementation produces the behavior. In particular, it
    > does not specify that extra code will be generated, nor
    > that the values will be stored in a "native" word size.
    >
    > If by "explicitly sized variable" you mean something
    > else, I need you to explain it to me.
    >
    > Advice: Use things like int_fast16_t when your program
    > needs the services they provide, and don't fret about micro-
    > optimizing UNTIL AND UNLESS you have measurements that show
    > it to be necessary. "Premature optimization is the root
    > of all evil."


    In fact such actions as masking off a long to 32 bits, or a char to
    8 bits, are very likely to be automatically optimized away by the
    code generator when unnecessary.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
     
    CBFalconer, Mar 16, 2005
    #3
  4. Adel

    Jack Klein Guest

    On 16 Mar 2005 08:40:58 -0800, "Adel" <> wrote in
    comp.lang.c:

    > Hello.
    > Is the statement below proved by the ANSI C standard?


    The C standard does not prove anything. It neither needs to nor
    attempts to.

    > "It is undesirable to use explicitly sized variables in functions as


    The word "undesirable" does not appear in the C standard.

    > auto variables or parameters. The values will always be stored as the


    The standard says nothing at all about how objects are laid out in
    memory, let alone any "always" about them.

    > processor native word size, and extra code will be generated by the
    > compiler to mask off bits that are not significant in the result."
    >
    > Adel


    If you want proof for a non-technical, opinionated statement that, if
    it can be answered at all, can only be answered for specific
    implementations on specific architectures, I would suggest you ask the
    person who made the statement to provide it.

    Tell them to put up or shut up, in other words.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Mar 17, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. thechaosengine

    Oddly sized sized password textbox

    thechaosengine, Sep 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    611
    David Hearn
    Sep 15, 2005
  2. =?Utf-8?B?V2FyYW4=?=

    Auto-Suggested Textbox like google auto suggest

    =?Utf-8?B?V2FyYW4=?=, Apr 20, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    8,573
    inrakeshworld
    Jul 27, 2007
  3. shsingh
    Replies:
    13
    Views:
    770
  4. linkswanted
    Replies:
    1
    Views:
    999
  5. Danny@Kendal

    Finding height of auto-sized element?

    Danny@Kendal, Sep 8, 2004, in forum: Javascript
    Replies:
    2
    Views:
    112
    Mike Foster
    Sep 8, 2004
Loading...

Share This Page