Olin Lathrop | 3 Jul 14:02

Re: [PIC] using BREAK in 'C'

Gerhard Fiedler wrote:
>> As you can see the variables declared with 'const' are really static
>> (like the 'static' directive in C) while the ones with the 'var' are
>> 'auto' variables (aka sits on the stack).
>
> I find this at least not intuitive. I'd expect a const to be constant.

In the Pascals I am familiar with CONST defines compile time symbolic
constants only.  Certainly my version works this way, although it often
realizes these constants as static read-only variables.

Note that Tamas' code doesn't prove how exactly the compiler interpreted the
CONST symbols.  Either interpretation would have resulted in the same
output.  For that matter his code doesn't even prove the constants are
static if they are implemented as values in memory locations.  Since you can
only read them and then you always read the same value, you can't tell
whether you are reading a different memory location each time or whether the
compiler is substituting the symbol's value on the fly.

The only way to tell would be to take the address of a symbolic constant.
If you get a compile error, then its just a symbolic constant.  If it works,
then you still don't know whether the compiler created a literal only
because you asked for the address.  You can pass a symbolic constant to a
subroutine pass by reference parameter and see if the the address changes
with nesting level.  If so, then these things aren't variables at all since
the compiler is creating the argument anew each call.

It's very tricky to tell the difference, which also makes it so you don't
need to care in most cases.

********************************************************************
Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.
--

-- 
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist


Gmane