MISRA Discussion Forums

Full Version: Rule 1.3 - Taking address of near auto variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

PC-Lint warn me that i'm using the address of a near auto variable.

My code looks like this:
/* static var */
static int16_t MySignVar = 0;

StatusType tMyfunc(void)
   uint16_t MyUnSignVar = 0U;
   StatusType ReturnValue;
   ReturnValue = tSomefunt(Parameter_1, &MyUnSignVar ); /* Note 934: Taking address of near auto variable... [MISRA 2012 Rule 1.3, required]... */
   /* MyUnSignVar is always positive */
   MySignVar += (int16_t)MyUnSignVar ;
   return (ReturnValue);

Could you help me to handle this issue?

although this forum is not intended to discuss tool specific questions (consider re-posting over at gimpel.com): the message can only occur if you are on a crusty old 16-bit platform (in PC-Lint terms spN != spF). Is that the case here or is PC-Lint not correctly adapted to your platform/compiler?
Hi, thank you for the reply.

Indeed, my intent is not to discuss about the tool ^^.
Let me reformulate:
1) Could you confirm me the misra failure?
2) In case of confirmed, how to handle it (software implementation)?

Thank in advance.
That depends on the memory model of your platform.
Do you have a segmented memory model with near and far pointers where tSomefunt could lie in a different segment than tMyfunc/&MyUnSignVar?
That could be a potential problem, because the near pointer loses the segment information.
Hence it was flagged with Rule 1.3 by Gimpel (Rule 1.3 collects all undefined behavior for which no specific Rule exists).
Didn't you see the lint size options -spN (=size of near pointer) and -spF (=size of far pointer) i mentioned?
Are they set up correctly according to your platform/compiler, or not?
Francois Wrote:1) Could you confirm me the misra failure?
Oh, I forgot to mention that near/far pointers are not a C language construct, so tagging this with MISRA Rule 1.3 is politically incorrect:).
It should be a regular info/warning.
Thank a lot for your answer.

You're right, lint documentation only talks about windows application and interaction with library...
My application will run in a 16-bits cpu with a strictly linear address space.

We will discuss about this during project meeting and probably decide to disable or justify the warning.

Thank you.
Rule 1.3 covers undefined behaviour as defined by The C Standard. Taking the address of a local variable is not C undefined behaviour.

Near and far pointers are implementation defined and so directive 1.1 and rule 1.2 apply. We can not comment on the behaviour of a particular tool or compiler extensions.