Re: [PIC] Learning C

Isaac Marino Bavaresco <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <[email protected]>
Em 19/11/2024 15:54, Harold Hallikainen escreveu:
>
> On Mon, November 18, 2024 11:54 pm, Forrest Christian (List Account) wrote:
>
>> In the context of detecting an overflow at runtime, one strategy that is
>> used is to initialize the stack memory to a known non-zero value and then
>> to verify that the top values never change.  If they do, you know that
>> something has overwritten them probably due to a stack overflow which can
>> be handled appropriately.
>>
> I've used this on a PIC24H. I have a function that fills the heap to the
> stack with 0xaa55. I ran the firmware with the Debugger (why does spell
> check want to capitalize that?) and then looked at RAM to make sure there
> was a large continuous block of 0xaa55.

I'm not sure if in this aspect the PIC24Hs are the same as the dsPICs, 
but the dsPICs have stack overflow checking implemented in hardware 
(there is a stack limit register).

If I remember it correctly, dsPICs and PIC24Hs are one of the rare 
architectures that the stack grows upwards (towards larger addresses).

> On the use of the address of a local variable to find the stack pointer, I
> THINK that in optimization, a compiler may decide to use a register
> instead of the stack, so anything like that needs to be tested.


If you take the address of a variable, that will force the compiler to 
allocate it in memory.


> On learning C, I really like it, but could use more knowledge on pointers,
> void types, and use of CONST. I generally think CONST means it is
> constant, does not change, and could be stored in flash. But I've seen
> stuff where that does not seem to be the case.


'const' only tells the compiler to prevent you from changing it by 
accident (and there are some ways to circumvent that).

In some architectures, const variables are allocated in FLASH/ROM, but 
it varies.


Cheers,

Isaac



>
> Harold
> https://w6iwi.org
>
>
>

-- 
O software antivírus Avast realizou uma checagem de vírus neste e-mail.
www.avast.com
-- 
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
https://mailman.mit.edu/mailman/listinfo/piclist
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.