SNMP question

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

SNMP question

Post by SeeCwriter »

I copied this function from an example in one of the NB manuals, and it works, but I have 2 questions. First, shouldn't pInfo be static since it's on the stack? Second, if I put a printf statement inside the if statement, before the return, why does the program crash almost every time it boots.

Code: Select all

const SysInfo * GetSysInfo()
{
	SysInfo *pInfo = ( SysInfo * ) GetUserParameters();
	if ( pInfo->valid == 0x12345678 )
	{
		return pInfo;
	}
       // initialize structure.
      ...
}
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: SNMP question

Post by pbreed »

Its part of the SNMP static initalization.
So it happens before the system is setup, hence a printf here will cause the system to try and print to i/o that is not setup.

Its getting the record directly out of flash, and its returning a pointer to that memory block.
Its not static because the pointer is just used to hold the return value, of a pointer, not hold the content of the structure....

If something else changes the record in flash then next time this info is gotten it will get the fresh flash contents...
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: SNMP question

Post by SeeCwriter »

Ah, that explains it. Thank you.

As an aside, in another thread I mentioned that when I turn on stack checking I get a warning in my MIB file telling me to reduce local variables. It turns out that the warning was caused by calling function SetSysInfo.

Code: Select all

void SetSysInfo( SysInfo si )
{
  si.valid = 0x12345678;  // You may want something more meaningful or robust.
  SaveUserParameters( &si, sizeof( SysInfo ) );
}
It's because the SysInfo structure is being passed on the stack. I overloaded the function with one that accepts a pointer to the structure and the warning went away.
Post Reply