piclist 2008\07\28\084607a >
Thread: Starting with C
picon face BY : Gerhard Fiedler email (remove spam text)

sergio masci wrote:

{Quote hidden}

Yes, of course (in a typical stack-based C implementation). But a local arr
ceases to exist after the end of the block, and during its lifetime its
address is constant. The next invocation of the function is a new life, so
to speak. I'm not sure where you want to go with this... arr, as declared
here, is defined as being constant, by the C standard.

If you want its address to be constant across invocations of the function
it is declared in, you just need to declare it static, but I'm sure you
know that. So if this is what you want, this is what you need to do. This
also means that even in a stack-based C implementation arr won't be on the
stack anymore. (Typically... :)

>> Not sure what you mean exactly, but AFAIK, for most purposes C is
>> defined in terms of "observable effects", which in this case means that
>> the whole content of main() could be optimized away -- there's no
>> guarantee that arr[2] ever gets set to anything, because it doesn't
>> create any observable effect. Does a falling tree make a noise if
>> nobody's there to hear it? :)
> Come on you can't base a function optimisation argument on what happens
> in "main"

FWIW, my preceding comment is valid for any function like the above
(whether main() or further down in the call tree), with a local variable
that is only set, never read and isn't declared volatile.

> XCSB has been doing this for years :-)

Always happy to provide opportunity for XCSB plugs :)


<1wjr6pxf9xoev$.dlg@connectionbrazil.com> 7bit

See also: www.piclist.com/techref/microchip/languages.htm?key=c
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Starting with C

month overview.

new search...