Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #3839

Re: Register storage type

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Register storage type
Date 2011-05-12 14:27 -0700
Organization None to speak of
Message-ID <lnaaerk3sg.fsf@nuthaus.mib.org> (permalink)
References <iqhhgg$d8j$1@speranza.aioe.org> <OeGdnRorOK1J11HQnZ2dnUVZ_gSdnZ2d@bestweb.net> <iqhiie$g5j$1@speranza.aioe.org>

Show all headers | View raw


Free Willy <nospam@nospam.com> writes:
> Kenneth Brody writes:
>> On 5/12/2011 4:55 PM, Free Willy wrote:
>>> Say the CPU has only AL, BL, CL, DL or eight 8 bit registers, and if
>>> want to declare 10 register variables in my code, is it possible to do
>>> it?
>>>
>>> Say size_of(float) is the same as size_of(int), is it possible to
>>> define a "register float" variable? How will the register get converted
>>> between int and float?
>> 
>> The "register" keyword is just a hint to the compiler, which it is free
>> to use or ignore as it sees fit.
>
> OK, but will it always give a warning if you try to assign too many 
> register variables for the CPU (or the wrong type of variable, if this 
> isn't supported), or just compile it possibly with errors or undefined 
> behaviors at runtime?

A compiler can warn about anything it likes, and some might give such a
warning, either by default or by the use of some command-line option.
But no such warning is required, and as far as I know most compilers
won't bother.

Declaring "too many" register variables won't cause errors or undefined
behavior.  The compiler isn't disobeying the "register" specifier, since
the specifier (in spite of the name) doesn't say to store the variable
in a register.

> Another question is array variables declared as register type - could the 
> compiler put a small array say of 3 elements into different registers and 
> translate array accesses to the right register?

If you declare an array variable as "register", you can't take its
address.  Since array indexing is defined in terms of addresses, such an
array variable is pretty much useless.

If you declare an array variable *without* "register", the compiler can
store it in one or more registers, as long as the behavior of the
program is not affected.  For example, if you take the address of one of
the elements of the array and pass it to some function, the compiler
isn't likely to be able to store it in a register, since the called
function woudnl't know how to access it.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Register storage type Free Willy <nospam@nospam.com> - 2011-05-12 20:55 +0000
  Re: Register storage type Kenneth Brody <kenbrody@spamcop.net> - 2011-05-12 17:02 -0400
    Re: Register storage type Free Willy <nospam@nospam.com> - 2011-05-12 21:13 +0000
      Re: Register storage type Angel <angel+news@spamcop.net> - 2011-05-12 21:20 +0000
      Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-12 14:27 -0700
        Re: Register storage type Kenneth Brody <kenbrody@spamcop.net> - 2011-05-13 13:20 -0400
          Re: Register storage type Free Willy <nospam@nospam.com> - 2011-05-13 21:30 +0000
            Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-13 15:50 -0700
              Different languages (Was: Register storage type) gazelle@shell.xmission.com (Kenny McCormack) - 2011-05-14 08:58 +0000
                Re: Different languages (Was: Register storage type) Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-14 10:09 +0100
              Re: Register storage type Free Willy <nospam@nospam.com> - 2011-05-14 21:27 +0000
                Re: Register storage type Ian Collins <ian-news@hotmail.com> - 2011-05-15 09:55 +1200
                Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-14 16:46 -0700
                Re: Register storage type Jens <jens.gustedt@gmail.com> - 2011-05-15 10:08 -0700
                Re: Register storage type James Kuyper <jameskuyper@verizon.net> - 2011-05-15 14:09 -0400
                Re: Register storage type David Thompson <dave.thompson2@verizon.net> - 2011-05-19 01:50 -0400
                Re: Register storage type Stephen Sprunk <stephen@sprunk.org> - 2011-05-15 00:27 -0500
                Re: Register storage type Angel <angel+news@spamcop.net> - 2011-05-15 12:56 +0000
                Re: Register storage type Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-15 11:54 -0400
                Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-15 17:43 +0000
                Re: Register storage type Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-18 23:37 -0700
                Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-19 14:37 +0000
                Drift: Linguistics (was Re: Register storage type) Kenneth Brody <kenbrody@spamcop.net> - 2011-05-19 13:17 -0400
                Re: Register storage type Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-19 11:05 -0700
                Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-19 19:08 +0000
                Re: Register storage type Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-24 00:39 -0700
                Re: Register storage type Ian Collins <ian-news@hotmail.com> - 2011-05-20 07:46 +1200
                Re: Register storage type Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-19 22:37 -0400
                Re: Register storage type Michael Press <rubrum@pacbell.net> - 2011-05-25 12:57 -0700
                Re: Register storage type pete <pfiland@mindspring.com> - 2011-05-15 09:09 -0400
      Re: Register storage type Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-12 21:57 -0400
  Re: Register storage type Angel <angel+news@spamcop.net> - 2011-05-12 21:14 +0000
    Re: Register storage type gordonb.unc3q@burditt.org (Gordon Burditt) - 2011-05-13 07:49 -0500
  Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-12 14:20 -0700
    Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-12 21:59 +0000
      Re: Register storage type BGB <cr88192@hotmail.com> - 2011-05-12 15:50 -0700
      Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-12 15:49 -0700
        Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-12 23:19 +0000
          Re: Register storage type Keith Thompson <kst-u@mib.org> - 2011-05-12 16:29 -0700
            Re: Register storage type Seebs <usenet-nospam@seebs.net> - 2011-05-13 00:15 +0000
  Re: Register storage type Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> - 2011-05-12 15:24 -0700
  Re: Register storage type Peter Nilsson <airia@acay.com.au> - 2011-05-12 17:39 -0700

csiph-web