Re: [PIC] Learning C

"Harold Hallikainen" <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <[email protected]>

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.

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.

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.

Harold
https://w6iwi.org



-- 
Not sent from an iPhone.
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.