Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Using explicitly sized variables in functions as auto variables or parameters

Reply
Thread Tools

Using explicitly sized variables in functions as auto variables or parameters

 
 
Adel
Guest
Posts: n/a
 
      03-16-2005
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

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      03-16-2005


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."

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      03-16-2005
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


 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      03-17-2005
On 16 Mar 2005 08:40:58 -0800, "Adel" <(E-Mail Removed)> 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/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto Shipping Auto Shipping Scheduling:car moving auto transport linkswanted ASP .Net 1 11-22-2013 07:02 AM
Oddly sized sized password textbox thechaosengine ASP .Net 1 09-15-2005 07:34 PM
Finding height of auto-sized element? Danny@Kendal Javascript 2 09-08-2004 04:36 PM



Advertisments