Short code to determine compiler's register use

Peter Desnoyers desnoyer at apple.com
Fri Jul 14 03:29:49 AEST 1989


In article <396 at uop.uop.EDU> greg at uop.EDU (Greg Onufer) writes:
> main(){{ /* block 1 */
>         int count1; /* Base of stackframe */
>         register x1, x2, ... {
>             int count2;
>         }}
>        { /* block 2 */
>         int count1;
>         register *x1, *x2, ... {
>             int count2; /* Base of new stackframe */
                                     ^^^^^^^^^^^^^^
> [...] (code has been brutalized to squeeze out lines)

Remember that the compiler does not have to create a new stack frame
when it encounters a block. It can just append the block variables
to the auto variables for the function and add initialization code
where needed. If it is smart it will know that auto variables in 
different blocks don't conflict and can use the same storage locations.

Try printing out the addresses of each instance of count1 and count2
on different compilers. That might give you some additional insight
into what is going on.

                                      Peter Desnoyers
                                      Apple ATG
                                      (408) 974-4469



More information about the Comp.lang.c mailing list